Feb 15, 2001 #1 Andel Programmer Feb 15, 2001 366 US Is there anyone who can tell me how to use variable in the FROM clause? Ex. declare @tblname varchar(50) set @tblname = mytable select * from @tblname The myTable has some records but this query doesn't give any result. Can somebody tell me the trick? Thanks!
Is there anyone who can tell me how to use variable in the FROM clause? Ex. declare @tblname varchar(50) set @tblname = mytable select * from @tblname The myTable has some records but this query doesn't give any result. Can somebody tell me the trick? Thanks!
Feb 15, 2001 1 #2 jballum MIS Jul 10, 2000 161 CA You have to build the string and then run it using exec (ie. dynamically). select @dynamicQuery = 'select * from ' + @tblname exec @dynamicQuery Give this a shot. JB Upvote 0 Downvote
You have to build the string and then run it using exec (ie. dynamically). select @dynamicQuery = 'select * from ' + @tblname exec @dynamicQuery Give this a shot. JB
Feb 15, 2001 Thread starter #3 Andel Programmer Feb 15, 2001 366 US JB, it works... Thank you! Maingel Upvote 0 Downvote