﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server 2008 - General  / Export sql query to CSV file / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 23 May 2013 23:04:30 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Export sql query to CSV file</title><link>http://www.sqlservercentral.com/Forums/Topic1422965-391-1.aspx</link><description>[quote][b]ilugopal (2/22/2013)[/b][hr]While I'm exporting sql query details to CSV file I get the column headers and after the column I get minus symbol below the column headers followed by the data. IS there a way where I can get only the column headers and not the minus symbol.Server_Name Instance_name User_name ------------- -------------- ----------xys.com          sql24              user1xys.com          sql24              user1xys.com          sql24              user1I dont want this "---------" symbol. I want the o/p asServer_Name Instance_name User_name xys.com          sql24              user1xys.com          sql24              user1xys.com          sql24              user1[/quote]How are you doing the export?  For example, are you using SQLCmd, BCP, or someother method?  I ask because it does make a real difference.</description><pubDate>Fri, 22 Feb 2013 16:01:14 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Export sql query to CSV file</title><link>http://www.sqlservercentral.com/Forums/Topic1422965-391-1.aspx</link><description>you could use BCP as well.[code="plain"]BCP "select col1+','+col2+','+col3 from dbo.table" queryout c:\temp\file.csv -c -T[/code]or if you have xp_cmdshell enabled you can run it from SSMS or sql agent(note: xp_cmdshell can be a security risk).[code="sql"]exec xp_cmdshell ''bcp "select col1+','+col2+','+col3 from dbo.table" queryout c:\temp\file.csv -c -T''[/code]</description><pubDate>Fri, 22 Feb 2013 07:54:11 GMT</pubDate><dc:creator>Robert klimes</dc:creator></item><item><title>RE: Export sql query to CSV file</title><link>http://www.sqlservercentral.com/Forums/Topic1422965-391-1.aspx</link><description>Two options in my opinion:-1 Run the query to grid then on the grid  Right click on grid -&amp;gt; Select all -&amp;gt;  Right click on grid -&amp;gt;copy with headers -&amp;gt; paste into excel save as CSV.2 If you want to run this on a scheduled basis use SSIS  to export the data as csv using a query along the lines of select Server_Name, Instance_name, User_name union all select col1, col2, col3 from table"</description><pubDate>Fri, 22 Feb 2013 04:16:08 GMT</pubDate><dc:creator>Stuart Davies</dc:creator></item><item><title>Export sql query to CSV file</title><link>http://www.sqlservercentral.com/Forums/Topic1422965-391-1.aspx</link><description>While I'm exporting sql query details to CSV file I get the column headers and after the column I get minus symbol below the column headers followed by the data. IS there a way where I can get only the column headers and not the minus symbol.Server_Name Instance_name User_name ------------- -------------- ----------xys.com          sql24              user1xys.com          sql24              user1xys.com          sql24              user1I dont want this "---------" symbol. I want the o/p asServer_Name Instance_name User_name xys.com          sql24              user1xys.com          sql24              user1xys.com          sql24              user1</description><pubDate>Fri, 22 Feb 2013 03:51:01 GMT</pubDate><dc:creator>ilugopal</dc:creator></item></channel></rss>