tags:

views:

48

answers:

1

Hi,

I'm working in SQL Server 2000. The following query is not working

declare @TempAccountKey Table (AccKey int,SitName varchar(1000),SitKey int) 
insert into @TempAccountKey(AccKey,AccName) 
exec [usp_Get_AccountForUser] @UserName 

It is throwing the error

EXECUTE cannot be used as a source when inserting into a table variable.

Any ideas?

#1


The linked server is properly set up. If i execute the following query

exec [ABC-SQL-PROD.DBabc.dbo.usp_Get_ABCForUser]

it is showing the error 'Could not find stored procedure'.

Any ideas?

NLV

+2  A: 

Use a temp table instead

CREATE TABLE #TempSiteKey (AccKey int,SitName varchar(1000),SitKey int) 

insert into #TempSiteKey (AccKey,AccName) 
exec [usp_Get_AccountForUser] @UserName 

DROP TABLE #TempSiteKey

And the reason you can't call the procedure is because you've delimited it incorrectly

exec [ABC-SQL-PROD.DBabc.dbo.usp_Get_ABCForUser]

Actually means execute the procedure called 'ABC-SQL-PROD.DBabc.dbo.usp_Get_ABCForUser'.

What you want is:

exec [ABC-SQL-PROD].[DBabc].[dbo].[usp_Get_ABCForUser]
Matt Whitfield
Cant i do that with table variable without using a temp table? I'm able to run this code perfectly in sql server 9.0. So does that mean 8.0 wont support this?
NLV
Correct. I didn't realize they finally added this in; it will definitely NOT work in SQL 2K with a table variable.
Joe
if you are just retrieving 1 row, you might want to consider using OUTPUT parameters instead of returning a result set.
Matt Whitfield
I'm retrieving multiple rows. I've created a temp table instead of using table variable. But the problem now is i'm not able to call the remote stored procedure. I've updated the problem in the question.
NLV
And I've updated my answer...
Matt Whitfield