Create/export csv file from sql server table

  • I need to create and export a csv file from an sql server table within a stored procedure. Help!!

  • An easy way is to create a DTS package that exports the file or table in csv format then call it inside your stored procedure like:

    exec master..xp_cmdshell 'dtsrun /S "ServerName" /U "UserName" /P "Password" /N "PackageName"'

  • or use BCP

    exec master..xp_cmdshell 'bcp database.owner.tablename out outputfilename -c -t "," -S servername -T'

     

    Far away is close at hand in the images of elsewhere.
    Anon.

  • Hello,

    This works, but I get character zero in null fields. Is there a way to eliminate these?

    Thanks

    Tom

Viewing 4 posts - 1 through 3 (of 3 total)

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