Facing a problem, it seems my data stored in SQL Server does not stored correctly, simply put, how to verify that a varchar data has carriage return and line feed in it? I try to print them out, does not show the special characters.
Thanks
Facing a problem, it seems my data stored in SQL Server does not stored
Share
You can use SQL Server’s
char(n)andcontains()functions to match on field contents in yourWHEREclause.The following SQL will find all rows in
some_tablewhere the values ofsome_fieldcontain newline and/or carriage return characters:To remove carriage returns in your
some_fieldvalues you could use thereplace()function long withchar()andcontains(). The SQL would look something like:To remove new lines you can follow up the last statement with the char(10) version of that update. How you do it all depends on what types of newlines your text contains. But, depending on where the text was inserted/pasted from the new lines may be \r\n or \n so running updates against both \r and \n characters would be safer than assuming that you’re getting one version of newline or the other.
Note that if the newlines were removed and you want to retain them then you have to fix the issue at the point of entry. You can’t replace or fix what has been removed so you should save the original text data in a new column that holds the original, unmodified text.