How to export data from TEMP table to CSV file

  • 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.

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


    I'm on LinkedIn

  • Thank you very much! It works!

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

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