BCP from a temporary table

  • Hi,

    Can you BCP the contents of a temporary table? I have created a temporary table, and I want to export the results to an ASCII file.

    Can I do this? If so, what would be the correct syntax?

    Thanks in advance

  • Greetings.. No BCP is very limited going out. You can do a bulk insert, but can't really export from transact SQL. To get around this I've used the following.

    xp_CMDShell 'BCP tempDB..#TempTable OUT tablename.dat -S -P -U etc.....'

    Good luck...

    Jim

  • Hey Jim how did you build your temp table as once xp_cmdshell you are no longer in the same scope as the rest of you query and thus the table should not be visible to bcp at that point.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • If you make the call in the Stored Proc that created the temp table, the object is still around until the proc terminates. Usually try to do some clean up after the call to make sure there is some T-SQL after the shell command.

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

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