I have a varchar column that contains the string lol\ncats
, however, in SQL Management Studio it shows up as lol cats
.
How can I check if the \n
is there or not?
We can use the CHARINDEX() function to check whether a String contains a Substring in it. Name of this function is little confusing as name sounds something to do with character, but it basically returns the starting position of matched Substring in the main String.
Remove and Replace Carriage Returns and Line Breaks in SQL Using SQL to remove a line feed or carriage return means using the CHAR function. A line feed is CHAR(10); a carriage return is CHAR(13).
The "N" prefix stands for National Language in the SQL-92 standard, and is used for representing Unicode characters.
SELECT * FROM your_table WHERE your_column LIKE '%' + CHAR(10) + '%'
Or...
SELECT * FROM your_table WHERE CHARINDEX(CHAR(10), your_column) > 0
Use char(13)
for '\r'
and char(10)
for '\n'
SELECT * FROM your_table WHERE your_column LIKE '%' + CHAR(10) + '%'
or
SELECT * FROM your_table WHERE your_column LIKE '%' + CHAR(13) + CHAR(10) + '%'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With