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.
    
        | 
                
                    | 
                            
                                | Author | Topic |  
                                    | VivekReddyStarting 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 errori want to use @temptable in dynamic sqlVivek.B |  |  
                                    | harsh_athalyeMaster 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 AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |  
                                          |  |  |  
                                    | madhivananPremature Yak Congratulator
 
 
                                    22864 Posts | 
                                        
                                          |  Posted - 2007-10-05 : 04:15:59 
 |  
                                          | quote:Make sure you read this fullywww.sommarskog.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to failOriginally 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 errori want to use @temptable in dynamic sqlVivek.B
 
 |  
                                          |  |  |  
                                |  |  |  |