February 22, 2013 at 3:51 am
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 user1
xys.com sql24 user1
xys.com sql24 user1
I dont want this "---------" symbol. I want the o/p as
Server_Name Instance_name User_name
xys.com sql24 user1
xys.com sql24 user1
xys.com sql24 user1
February 22, 2013 at 4:16 am
Two options in my opinion:-
1 Run the query to grid then on the grid Right click on grid -> Select all -> Right click on grid ->copy with headers -> 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"
-------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
I would never join a club that would allow me as a member - Groucho Marx
February 22, 2013 at 7:54 am
you could use BCP as well.
BCP "select col1+','+col2+','+col3 from dbo.table" queryout c:\temp\file.csv -c -T
or if you have xp_cmdshell enabled you can run it from SSMS or sql agent(note: xp_cmdshell can be a security risk).
exec xp_cmdshell ''bcp "select col1+','+col2+','+col3 from dbo.table" queryout c:\temp\file.csv -c -T''
February 22, 2013 at 4:01 pm
ilugopal (2/22/2013)
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 user1
xys.com sql24 user1
xys.com sql24 user1
I dont want this "---------" symbol. I want the o/p as
Server_Name Instance_name User_name
xys.com sql24 user1
xys.com sql24 user1
xys.com sql24 user1
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.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy