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)
 Problem with sp_executesql

Author  Topic 

rksingh024
Yak Posting Veteran

56 Posts

Posted - 2002-06-05 : 05:56:04
When I run this query it gives me the following error:
"Must declare the variable '@table1'"
-------------------
declare @table1 table(col1 int)
declare @x decimal(9,2),
@sql nvarchar(1000)

insert into @table1 values(200)

SELECT @sql = N'SELECT @x=ISNULL(AVG(col2),0) FROM table2
WHERE col1 IN (SELECT col1 FROM @table1)'

EXEC sp_executesql @sql,N'@table1 table(col1 int),@x decimal(9,2) OUTPUT', @table1, @x OUTPUT

print @x
-----------

Table2 exists in the database with column col2
Could you please help me out. Is it possible to use table variable in sp_executesql statement?

Ramesh

VyasKN
SQL Server MVP & SQLTeam MVY

313 Posts

Posted - 2002-06-05 : 06:12:06
I don't think this is possible. You can only return table variables from User Defined Functions, but you can't pass them to stored procedures this way.

--
HTH,
Vyas
http://vyaskn.tripod.com
Go to Top of Page
   

- Advertisement -