Home Table name as variable
Reply: 0

Table name as variable

user403 Published in June 18, 2018, 3:32 am

I am trying to execute this query:

declare @tablename varchar(50)
set @tablename = 'test'
select * from @tablename

This produces the following error:

Msg 1087, Level 16, State 1, Line 5

Must declare the table variable "@tablename".

What's the right way to have table name populated dynamically?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.407549 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO