Avatar of CipherIS
CipherIS
Flag for United States of America asked on

SQL Find Carriage Return and Delete it.

Trying to write an SQL Script that will find a carriage return and delete it.  When I export the data to excel the carriage return is causing data to go to the next line and into the first field.
SELECT *,
	CASE comment
	WHEN CHARINDEX(CHAR(10), comment) Then
		'True 10'
	WHEN CHARINDEX(CHAR(13), comment) Then
		'True 13'
	ELSE
		'False'
	END AS CheckReturn 
FROM #Temp

Open in new window

Attempting to run the above code I receive error:

Msg 8114, Level 16, State 5, Line 34
Error converting data type varchar to bigint.
SQLMicrosoft SQL Server

Avatar of undefined
Last Comment
CipherIS

8/22/2022 - Mon
Vitor Montalvão

What's the data type for comment column?
ASKER CERTIFIED SOLUTION
ste5an

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
CipherIS

ASKER
Also found this.

https://robbamforth.wordpress.com/2009/02/25/sql-remove-hidden-line-feed-carriage-return-from-a-field/

delete from TABLE
where FIELD1 like ‘%’+CHAR(13)+’%’

delete from TABLE
where FIELD1 like ‘%’+CHAR(10)+’%’

Open in new window


So after I put my data into a temp table I can use above to delete the carriage returns.  Works great.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes