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 2005 Forums
 Other SQL Server Topics (2005)
 using dymamic sql

Author  Topic 

VivekReddy
Starting Member

2 Posts

Posted - 2007-10-05 : 03:16:32
how to use table variable in dynamic sql?

ex : declare @temptable table (id int, name varchar(50))
execute (' select * from @temptable ' )
the above statement giving error
i want to use @temptable in dynamic sql

Vivek.B

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-10-05 : 04:07:05
Because it is out of scope. You need to include table definition inside EXEC as well.

Execute('declare @temptable table (id int, name varchar(50)); select * from @temptable ' )


But frankly why do you need this?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-05 : 04:15:59
quote:
Originally posted by VivekReddy

how to use table variable in dynamic sql?

ex : declare @temptable table (id int, name varchar(50))
execute (' select * from @temptable ' )
the above statement giving error
i want to use @temptable in dynamic sql

Vivek.B


Make sure you read this fully
www.sommarskog.se/dynamic_sql.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -