• ahthomas (1/2/2013)


    I have a script that writes data to a temp table. I need to automatically export this to a csv located at a UNC destination. How do I write this into the SQL script? A retention period in this would also be nice...

    TSQL doesn't have a native ability to export to disk; you have to use something like xp_cmdshell to call bcp.exe or some other component

    You can also use a CLR function like this one:http://sqlclrexport.codeplex.com/

    There's a connect item that will never be fulfilled asking for a the export equivalent of BULK INSERT, but MS says they will not complete the request.

    http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=224026

    https://connect.microsoft.com/SQLServer/feedback/details/512367/new-t-sql-bulk-export-bulk-write-statements

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!