Sunday, April 24, 2016

Loading data into SQL Server that has Carriage Returns, Line Feeds, and Commas

1) Run someting like the following to generate your data set.  Note the end result will be a text file that is bar, |, delimited.

SELECT CONCAT(
number,
'|',
CONVERT(VARCHAR, [begin]),
'|',
REPLACE ( descript , CHAR(13) + CHAR(10) , ' ' ), -- AS descript,
'|',
REPLACE ( Notes , CHAR(13) + CHAR(10) , ' ' ), -- AS Notes,
'|',
REPLACE ( s_notes , CHAR(13) + CHAR(10) , ' ' )) -- AS s_notes
FROM stage.LeaseDuplicates;

2) Save the data set as a text file.

3) Import into Excel selecting the bar, |, as the delimiter.

No comments:

Post a Comment