October 11, 2006 at 2:12 am
Hi,
Hope that someone can help me on this one.
I have a Local variable containing a tablename and would like to do a select from the table in the variable.
Something like this: Select XX from @Variable
/Henrik
October 11, 2006 at 2:53 am
Would you mind to look around a little?
There is an answer on your question on the 1st page of this forum and couple of answers on the second page.
Happy browsing.
_____________
Code for TallyGenerator
October 11, 2006 at 2:54 am
You will have to use dynamic SQL.
exec('SELECT xx FROM ' + @Variable)
October 11, 2006 at 7:15 am
And, you need to be real careful if this comes anywhere near a GUI... think "SQL Injection". Theres a huge amount of info on how to prevent it... do a search for "SQL Injection" on Google.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply