Alex Thomas
Ten Centuries
Points: 1120
More actions
October 11, 2006 at 9:05 am
#113875
bit of a quickie here, but is there any way to use variables in select statements to define column or table names?
ie:
select @columnname from @tablename...
im guessing for the tablename you could use #tablename, ie a temp table perhaps?
Thanks
Ray M
SSC-Insane
Points: 21093
October 11, 2006 at 9:52 am
#665257
Why would you want to do that?
Here is a must read if your thinking of going down this road.
http://www.sommarskog.se/dynamic_sql.html
Mark Harr
SSCrazy Eights
Points: 9921
October 11, 2006 at 3:45 pm
#665324
No, you cannot use variables in that way, directly.
But you can construct a SQL text variable, and use sp_executesql to run the query. But be aware of the warnings Ray referred to about dynamic sql.
Hope this helps
Mark
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply