SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 using dymamic sql
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

VivekReddy
Starting Member

India
2 Posts

Posted - 10/05/2007 :  03:16:32  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
5509 Posts

Posted - 10/05/2007 :  04:07:05  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
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

India
22755 Posts

Posted - 10/05/2007 :  04:15:59  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000