I have to make exports of multiple tables where i have to put double quotes over comma’s and over a double quote. It has to be a CSV export and each column needs a double quote at the start and end as well. Is there a way to generate this in SQL? Each export contains several different columns per export.
Good to know, I’m using Management Studio 20. I saw in earlier versions the option “Quote strings containing list operators when saving .csv results”, but that option is not available anymore.
I have now generated:
SELECT CONCAT('"', REPLACE(REPLACE([ProductDescriptionID], ',', '","'), '"','"""'), '"') as [ProductDescriptionID]
,CONCAT('"', REPLACE(REPLACE([Description], ',', '","'), '"','"""'), '"') as [Description]
,CONCAT('"', REPLACE(REPLACE([rowguid], ',', '","'), '"','"""'), '"') as [rowguid]
,CONCAT('"', REPLACE(REPLACE([ModifiedDate], ',', '","'), '"','"""'), '"') as [ModifiedDate]
,[Description]
FROM [AdventureWorks2022].[Production].[ProductDescription]
But i have to repeat it for each table
Luuk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.