January 2010
Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Search

 
Catagories
Archives
Recent Entries
Links
RSS
quote delimited CSV output for SQL
Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
November 12, 2009 11:33 AM

sql server

when you output sql text manually creating CSV file output format, you may need to adjust for quote delimited data if that data contains your delimeter or line feeds.

this code snippet is for 'comma' delimited output.

SELECT
  CASE PATINDEX('%[,"\r\n]%', [MyColumnData])
  WHEN 0 THEN [MyColumnData] -- not found
  WHEN NULL THEN [MyColumnData] -- unknown
  ELSE '"' + REPLACE([MyColumnData],'"','""') + '"' -- encode data
END
AS [MyEncodedOutput]





Comments

Post a comment
Name:


Email Address:


URL:


Comments: