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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Concatenate the dbname to table name

Author  Topic 

razeena
Yak Posting Veteran

54 Posts

Posted - 2012-07-12 : 02:36:45

Is it possible to concatenate the dbname passed to the table name
dynamically?
Below code is throwing error.
-------------
declare @t1 varchar(100)
set @t1 = 'dbname'
set @t1 = (@t1)+'.dbo.<mytablename>'
print @t1
select * from @t1
---------------

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-07-12 : 02:55:34
see here:
http://www.sommarskog.se/dynamic_sql.html


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-12 : 09:40:03
why is db changing at runtime? are you trying to iterate through multiple db while executing queries?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -