Writing table data to a file

  • Hello All,

    I'm looking for a way to write the data in a table to .CSV file using T-SQL. Is there any function in SQLServer 2005 (Some thing like UTL_FILE.PUTLINE in Oracle) using which I can achieve it.

    Your help is greatly appreciated.

    Thanks,

    -Amith Vemuganti

  • You can use the bcp utility (look it up in Books Online) invoked via xp_cmdshell (look it up in Books Online). T-SQL is powerful and can be used to solve many problems, but it should not be used to solve every problem.

    A much more appropriate alternative to export data from SQL Server to files would be using a client application; xp_cmdshell requires elevated permissions, and allows users with sufficient privileges to execute practically any OS command through SQL Server. As you can imagine, this represents a very serious potential threat to the system.

    On the other hand, you can also use SSIS which would require even less effort on your part and at the same time allow you to keep the data store as safe as it should be. Look for examples at http://www.sqlis.com/[/url] or search SQL Server Central (e.g. http://www.sqlservercentral.com/search/?cx=000517265726492607871%3Agqdiynsp-y0&cof=FORID%3A9&q=SSIS+export+data+to+file&sa=Go#1110).

    ML

    ---
    Matija Lah, SQL Server MVP
    http://milambda.blogspot.com

Viewing 2 posts - 1 through 1 (of 1 total)

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