Export to comma delimited csv

  • So I have a query running already that executes a sqlcmd command to export the results of a query to a csv. Seems to only come out as tab delimited rather than comma delimited. How do I switch this to comma delimited?

  • Can you give an example of what you are running? I usually use the bcp command and use the option -t,

    check out the 2 links below:

    http://msdn.microsoft.com/en-us/library/ms191485.aspx

    http://msdn.microsoft.com/en-us/library/ms162802.aspx

  • Here's the sqlcmd command, produces tab delimited data rather than comma.

    declare @sql varchar(8000)

    set @sql= 'SQLCMD.EXE -d SynDocsDB -i D:\MSSQL\SSIS\export.sql -o \\csg-cold01\cold\ABD\export'+ @datesql+ '.csv -s"," -W '

    print @sql

    exec xp_cmdshell @sql

  • This is interesting, when I run something very similar to this I get a comma delimated file. Are you sure that you are looking at the file in the correct location? Are there any errors when executing the cmd shell?

  • No errors.

    Output is like this:

    Something<tab>something<tab>something

    Not:

    something,something,something

  • Try not puting the quotes around the comma just use -s,

    If that still doesn't work try -s"|"

    and let me know the results.

  • That worked.

    Sent results to the parties who requested it, let's hope they like it. 🙂

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply