MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 22nd, 2006, 12:51 PM
alvincks alvincks is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 15 alvincks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 29 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old July 22nd, 2006, 02:38 PM
marnixR's Avatar
marnixR marnixR is offline
i don't do negative rep
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2006
Posts: 688 marnixR User rank is Major (30000 - 40000 Reputation Level)marnixR User rank is Major (30000 - 40000 Reputation Level)marnixR User rank is Major (30000 - 40000 Reputation Level)marnixR User rank is Major (30000 - 40000 Reputation Level)marnixR User rank is Major (30000 - 40000 Reputation Level)marnixR User rank is Major (30000 - 40000 Reputation Level)marnixR User rank is Major (30000 - 40000 Reputation Level)marnixR User rank is Major (30000 - 40000 Reputation Level)marnixR User rank is Major (30000 - 40000 Reputation Level)marnixR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 10 h 54 m 18 sec
Reputation Power: 372
should you as part of your stored procedure first check whether #TMP_CUSTOMER exists, and if it doesn't, create it ?

Reply With Quote
  #3  
Old July 22nd, 2006, 09:04 PM
alvincks alvincks is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 15 alvincks User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 29 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old July 23rd, 2006, 04:35 AM
marnixR's Avatar
marnixR marnixR is offline
i don't do negative rep
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2006
Posts: 688 marnixR User rank is Major (30000 - 40000 Reputation Level)marnixR User rank is Major (30000 - 40000 Reputation Level)marnixR User rank is Major (30000 - 40000 Reputation Level)marnixR User rank is Major (30000 - 40000 Reputation Level)marnixR User rank is Major (30000 - 40000 Reputation Level)marnixR User rank is Major (30000 - 40000 Reputation Level)marnixR User rank is Major (30000 - 40000 Reputation Level)marnixR User rank is Major (30000 - 40000 Reputation Level)marnixR User rank is Major (30000 - 40000 Reputation Level)marnixR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 10 h 54 m 18 sec
Reputation Power: 372
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

Reply With Quote
  #5  
Old August 1st, 2006, 08:46 PM
wisenut wisenut is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 4 wisenut User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 4 m 4 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Why bcp cannot detect temporary table ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT