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 |
stahorse
Yak Posting Veteran
86 Posts |
Posted - 2014-02-07 : 03:11:32
|
I have this querydeclare @TableName varchar(50)set @TableName = 'Hosea_tblDATA_NOTES'select * from @TableNameHosea_tblDATA_NOTES is the name of the table, I'm passing it to the parameter then select from it.as it is not working, with error "Must declare the table variable "@TableName"." How can I achive that, to pass a table name as a parameter to a query then use that name of the table inside the query to select from it. |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-10 : 09:06:05
|
quote: Originally posted by stahorse I have this querydeclare @TableName varchar(50)set @TableName = 'Hosea_tblDATA_NOTES'select * from @TableNameHosea_tblDATA_NOTES is the name of the table, I'm passing it to the parameter then select from it.as it is not working, with error "Must declare the table variable "@TableName"." How can I achive that, to pass a table name as a parameter to a query then use that name of the table inside the query to select from it.
why is table dynamic here? ideally you write separate retrieve procedure for each entity------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|