Link to home
Start Free TrialLog in
Avatar of Varshini S
Varshini S

asked on

SQL QUERY TO CSV WITH COLUMN HEADER

I am using following BCP command to export the SQL out put to CVS file. But it is missing the column header. How do I add the column header in the CSV out put ?      

      select @sql = 'bcp "exec '+  'usp_EmployeeDetails]'''+ @myDate+ '''" queryout ' + @Path + '.csv -c -t, -T -S'+ @@sname

      EXEC master..xp_cmdshell @sql
ASKER CERTIFIED SOLUTION
Avatar of Surendra Nath
Surendra Nath
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi

the way to do this is use a query like so:
  bcp "select 'col1', 'col2',.. from dbo.myTableout" queryout myTable.csv /SmyServer01 /c /t, -T

Open in new window