Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server DTS
|
SQL Server DTS Discussion specific to Data Transformation Service with SQL Server. General SQL Server discussions should use the general SQL Server forum. Readers of the book Professional SQL Server 2000 DTS with questions specific to that book should post in that book forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server DTS section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 13th, 2004, 04:02 PM
Registered User
 
Join Date: Jul 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using Temp Table as Source Error

I have a DTS package on server A that calls a stored procedure on Server B (non-linked servers). The stored proc creates and returns data from a temp table. See the following for an example of the stored proc (very stripped down!):
Code:
CREATE PROCEDURE usp_temp
AS
create table #temp (item varchar(20))
insert #temp 
select item from mytable

select * from #temp 
drop table #temp
The trouble is when I call this stored proc in an Execute SQL Task (or Transform Data Task) it states that there is an Invalid Object Name: #temp. I read that stored procs that use temp tables cannot be used as the source for these objects, but it says I can use a global temp table. I tried changing the stored proc code to use ##temp, but to no avail. One further issue is that the agent account that will run the job will not have create rights on Server A, so a permanent table is not an option.

Thoughts?
 
Old July 14th, 2004, 05:02 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

I believe for table variables, that you need permission to tempDB. You can use a table variable, as such:

declare table @temp
(
  item varchar(20)
)

insert into @temp
select item from mytable
...

Works the same, except table variables use memory allocations and that the stored proc cleans up the table variable when it stops running.

Brian
 
Old July 15th, 2004, 07:44 AM
Authorized User
 
Join Date: Jul 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What version of SQL Server are you using? I was wondering if using a user defined function that returns a table variable would work for you. This would only work if you are using SQL 2000 on the server you are pulling data from.

Good luck!
Jeff

 
Old July 15th, 2004, 01:33 PM
Registered User
 
Join Date: Jul 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I switched to using a table variable (@temp instead of #temp) and changed the maining code accordingly. Works fine now. According to Micr$oft, this is by design.

One other note for others...if attempting to execute this stored proc using VBScript (ActiveX) and inserting into a recordset, the line "SET NOCOUNT ON" must be added to the stored proc or the recordset will be closed! That took several hours to figure out! uggh.

 
Old July 15th, 2004, 03:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

That's odd. I wonder if that is a known bug...





Similar Threads
Thread Thread Starter Forum Replies Last Post
temp table in query abdusalam Access 5 January 9th, 2008 09:28 AM
TEMP TABLE TO REAL TABLE pallone SQL Server 2000 2 June 15th, 2007 07:50 AM
Copy whole structure of table in #temp table maulik77 SQL Server 2000 2 December 21st, 2006 02:42 AM
global temp table vs.permanent table use sofya SQL Server 2000 0 December 17th, 2004 01:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.