I am trying to fix Microsoft word smart quotes (and other word smart characters) that were inserted into some content due to copy/paste. While we are working on a permanent solution to this I am trying to create a script so we can fix the data as it becomes an issue.
To test it out I”m running the following query: select title from DigArticleArticle where ArticleId = 8249. This correctly retrieves our title, complete with the question mark due to the invalid character. To replace this I tried the following query:
select REPLACE(title, CHAR(8216), char(39)), Title from DigArticleArticle where ArticleID = 8249
This returns null as the first column. Why would my replace return null? Even if the character code isn’t found it should still return the original string.
From the MSDN Docs on the argument for char
8216 is larger than 255 so its null
For replace
So you’ll always get back null if
char(8216)is an argument in replaceAs per trekstuff’s answer you should use nchar instead