Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid chars on Course Titles #2533

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/Dfc.CourseDirectory.Database/Scripts/Script.PostDeploy.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8621,3 +8621,60 @@ WHEN NOT MATCHED
)
WHEN NOT MATCHED BY SOURCE
THEN DELETE;

--- FIND INVALID CHARS AND REPLACE WITH VALID CHARS ----------------
WHILE (EXISTS( Select CourseId,CourseRunId
from Pttcd.CourseRuns
where CourseName like '%&#%' and CourseRunStatus = 1))
BEGIN
With cte as (
Select coursename,courseid,courserunid,
patindex('%&#%',CourseName) as [FirstPosition],
substring(CourseName,patindex('%&#%',CourseName),1) as [FirstInvalidCharacter],
ascii(substring(CourseName,patindex('%&#%',CourseName),1)) as [FirstASCIICode]
from Pttcd.CourseRuns
where CourseName like '%&#%' and CourseRunStatus = 1),

cte2 as(
Select *,
substring(CourseName,FirstPosition,len(CourseName)-1) as PartialCourseName
from cte),

DataWithPos as (
Select *, patindex('%;%',PartialCourseName) as [LastPosition],
substring(PartialCourseName,patindex('%;%',PartialCourseName),1) as [LastInvalidCharacter],
ascii(substring(PartialCourseName,patindex('%;%',PartialCourseName),1)) as [LastASCIICode]
from cte2),

DataWithIs as (
Select *,substring(CourseName,FirstPosition,LastPosition) AS [InvalidString] from DataWithPos),

DatawithChar as (Select *,
CASE WHEN InvalidString = '–' OR InvalidString = '–' THEN
'-'
WHEN InvalidString = '’' OR InvalidString = ''' OR InvalidString = '’' OR InvalidString = ''' THEN
''''
WHEN InvalidString = '&' THEN
'&'
WHEN InvalidString = '+' THEN
'+'
WHEN InvalidString = '	' THEN
''
WHEN InvalidString = ' ' THEN
' '
END AS CharToReplace
from DataWithIs)
UPDATE CR
SET CR.COURSENAME = REPLACE(CR.CourseName,DC.InvalidString,DC.CharToReplace)
FROM Pttcd.CourseRuns as CR
JOIN DataWithChar as DC ON CR.CourseId = DC.CourseId AND CR.CourseRunId = DC.CourseRunId
END


UPDATE FC
SET FC.COURSENAME = CR.COURSENAME
FROM Pttcd.FindACourseIndex AS FC
JOIN Pttcd.CourseRuns as CR ON CR.CourseId = FC.CourseId AND CR.CourseRunId = FC.CourseRunId
WHERE FC.CourseName != CR.CourseName