views:

59

answers:

2

Using ColdFusion and Microsoft SQL we are exporting data to an Excel Spreadsheet using the cfx_excel plugin. The data contains a varchar(6000) which has CHAR(13)/line-breaks inputted in each entry.

The line-breaks are appearing as square brackets every time the report is generated in Excel format.

How would I go about removing the CHAR(13) within a SQL query?

Thank you.

+1  A: 

try this

update YourTable
set YourColumn =replace(YourColumn,CHAR(13),'')

or just for a select

SELECT replace(YourColumn,CHAR(13),'')
FROM YourTable

for char(10) and char(13) you can do this

SELECT replace(replace(YourColumn,CHAR(13),''),CHAR(10),'')
FROM YourTable

'' will replace it with a blank, if you want a space then use ' ' instead of ''

SQLMenace
Is this possible with a SELECT MyTable?
Alex
yes, see 2nd query
SQLMenace
This is so close to working :)Is there a way for me to replace two items (CHAR13 and CHAR10) per REPLACE?,replace(n.NOTE,CHAR(10),'') as [Comments]
Alex
see 3rd query, you can nest REPLACE
SQLMenace
Thank you VERY much! Works perfectly :)
Alex
char(13)char(10) = \r\n, aka carriage return + newline, which is what windows line breaks are made of. A single replace will do.SELECT REPLACE(YourField,CHAR(13)+CHAR(10),'') AS YourField FROM YourTable
Mark
As a note, if you do this as an update (and on insert for new records) it will be a good bit more efficient than doing it on every select in your webapp.
Ben Doom
A: 

To replace both char(10) and char(13) you should be able to just do a replaceList(textToReplaceIn,"#chr(10)#,#chr(13)#",","). If that doesn't work you can just do 2 replaces as in replace(replace(textToReplaceIn,chr(10),"","all"),chr(13),"","all")

remotesynth