Need to export fields containing linebreaks as a CSV from SQL Server

I don’t see where you will have much success exporting html to csv – it’s really not what csv is meant for. You would be better off using an xml format, where the html code can be enclosed in a cdata element.

That said, you could try using the Replace function to remove the line breaks, and you could manually add the quotes – something like this:

select '"' + replace (replace (html, char(10), ''), char(13), '') + '"'

If your html value could have double quotes in it, you would need to escape those.

Leave a Comment

tech