Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Temp table dump to txt file

Author  Topic 

MikeB
Constraint Violating Yak Guru

387 Posts

Posted - 2008-07-23 : 12:40:49
I have created a temp table, now I want to dump the contents into a text file.

The table is created properly, but when it comes to writing the text file, I get a couple of warnings and erros.

Here is the code from the s-proc to write the contents out to file:

SELECT * FROM #Accounts
declare @sql varchar(8000)
SELECT @sql = 'bcp tempdb..#accounts out i:\ExportFiles\Test.txt -c -t, -T -S ' + @@servername
exec master..xp_cmdshell @sql


Here are the errors and warnings:


SQLState = 01000, NativeError = 2701
Warning = [Microsoft][ODBC SQL Server Driver][SQL Server]Database name 'tempdb' ignored, referencing object in tempdb.
SQLState = 01000, NativeError = 2701
Warning = [Microsoft][ODBC SQL Server Driver][SQL Server]Database name 'tempdb' ignored, referencing object in tempdb.
SQLState = S0002, NativeError = 208
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name '#accounts'.


Any suggestions?

Mike B

pootle_flump

1064 Posts

Posted - 2008-07-23 : 12:42:41
you'll need to use a global temp table, or a permanent one. That one is out of scope.
Go to Top of Page
   

- Advertisement -