|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Why bcp cannot detect temporary table ?
hi, good day, i facing a problem
Code:
CREATE PROCEDURE [SP_TEST] AS SELECT * INTO #TMP_CUSTOMER FROM O_CUSTOMER ------------------------------------------------------------------------- SELECT DISTINCT COUNT(CUST_CD) FROM #TMP_CUSTOMER GO when i run in query analyzer , using "exec SP_TEST" , it work and display result but when run Exec Master..xp_CmdShell 'bcp "exec mydbtest..SP_TEST " queryout C:\TEST.TXT -c -Slocalhost -Usa -Ppassword' it give error "SQLState = S0002, NativeError = 208" and show Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name '#TMP_CUSTOMER'. thanks for guidance |
|
#2
|
||||
|
||||
|
should you as part of your stored procedure first check whether #TMP_CUSTOMER exists, and if it doesn't, create it ?
|
|
#3
|
|||
|
|||
|
as i know temporary not necessary to check it existing , cause it is temporary table , so it will create in every new thread and drop after use , correct me if i wrong
|
|
#4
|
||||
|
||||
|
not sure about temp files since i hardly ever use them, but it can't hurt to try a belts-and-braces approach and see if it solves the problem
|
|
#5
|
|||
|
|||
|
Exec Master..xp_CmdShell 'bcp "exec mydbtest..SP_TEST " queryout C:\TEST.TXT -c -Slocalhost -Usa -Ppassword'
Here the question is whether you r running this outside the body of the Stored Proc or not. When you create a temporary table it is in scope for either the duration of the batch (Local Temporary Table) or for the duration of the connection (Global Temporary Table.) A Local Temporary Table is identified by a single pound sign (#TempTable). A Global Temporary Table is identified by a double pound sign (##TempTable). The #temp tables has only scope with in the Stored procedures and it gets dropped after that. Try running your master...xp_cmdshell bcp inside the sp itself Another point is that the #temp tables are stored in tempdb database and not your normal database, so you might give a try like SELECT * FROM tempdb..tablename Thanks Wisenut |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Why bcp cannot detect temporary table ? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|