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

后端 未结 9 614
野的像风
野的像风 2020-12-28 13:49

I\'m running a query from SQL Server Management Studio 2005 that has an HTML file stored as a a string, e.g.:

SELECT html 
FROM table 

Thi

9条回答
  •  长情又很酷
    2020-12-28 14:11

    SQL Server Import and Export Data tool, FTW!

    Start -> Programs -> Microsoft SQL Server -> Import and Export Data

    Sample query:

    select *
    from (
    select 'Row 1' as [row], 'Commas, commas everywhere,' as [commas], 'line 1
    line 2
    line 3' as [linebreaks]
    
    union all 
    
    select 'Row 2' as [row], 'Nor any drop to drink,' as [commas], 'line 4
    line 5
    line 6' as [data]
    ) a
    

    CSV output:

    "row","commas","linebreaks"
    "Row 1","Commas, commas everywhere,","line 1
    line 2
    line 3"
    "Row 2","Nor any drop to drink,","line 4
    line 5
    line 6"
    

    Disclaimer: You may have to get creative with double-quotes in the data. Good luck!

提交回复
热议问题