0

I need help in export data from table to excel file using sql query. and with header and footer.

I used master..xp_cmdshell with passing db name, table name, and path where I store excel file any buddy can solve this. and any other way like query through export data to excel.

I must say I want to solve problem using query only. because I require only query.

Rajuu Parmar
  • 59
  • 10

1 Answers1

0

If you need column headers the best way to export to a CSV file (which EXCEL will open) is by using sqlcmd. The syntax is something like:

c:\>sqlcmd -S servername -i c:\path\yourqueryfilename.sql -o C:\OutputPath\AFilename.csv -s","

See http://msdn.microsoft.com/en-us/library/ms162773.aspx to find the complete command line options available for SQLCMD.

JohnS
  • 1,942
  • 1
  • 13
  • 16