How to export data from TEMP table to CSV file

  • rkordonsky 63916

    Mr or Mrs. 500

    Points: 587

    I am using the following statement:

    EXEC master..xp_cmdshell 'BCP "Select * from #tempTable" QUERYOUT E:\Temp\Sal1.csv -c -t "|" -T -S myserver'

    Here is the errors I received:

    NULL
    Starting copy...
    SQLState = S0002, NativeError = 208
    Error = [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Invalid object name '#tempTable'.
    SQLState = S1000, NativeError = 0
    Error = [Microsoft][ODBC Driver 11 for SQL Server]Unable to resolve column level collations
    NULL
    BCP copy out failed
    NULL

    If the Table is permanent I have no problem. But I do not want to create permanent table for every data output result. Can this situation be resolved without using permanent table.

  • PB_BI

    SSCoach

    Points: 17093

    You need to use a global temporary table rather than a local one. So ##temptable instead of #temptable


    I'm on LinkedIn

  • rkordonsky 63916

    Mr or Mrs. 500

    Points: 587

    Thank you very much! It works!

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

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