views:

1215

answers:

5

SQL query for a carriage return in a string and ultimately removing carriage return

I have some data in a table and there are some carriage returns in places where I don't want them. I am trying to write a query to get all of the strings that contain carriage returns.

I tried this

select * from Parameters
where Name LIKE '%"\n" %'

Also

select * from Parameters
where Name LIKE '\r'

'

Both are valid SQL but are not returning what I am looking for. Do I need to use the Like command or a different command? How do I get the carriage return into the query?

The carriage return is not necessarily at the end of the line either (may be in the middle).

A: 

Omit the double quotes from your first query.

... LIKE '%\n%'
Byron Whitlock
A: 

Something like SELECT * FROM Parameters WHERE Name LIKE '%\n%' seems to work for me.

djc
+3  A: 

this will be slow, but if it is a one time thing, try...

select * from parameters where name like '%'+char(13)+'%' or name like '%'+char(10)+'%'
KM
+1  A: 

You can also use regular expressions:

SELECT * FROM Parameters WHERE Name REGEXP '\n';
JYelton
+2  A: 

In SQL Server I Would use

where charindex(char(13), name)<>0
HLGEM