Hi all,
Simple question...
I have a stored procedure-- I want to be able to change the database I copy data from and to. Below is a simple example... I cannot figure out why I am unable to use a variable for the database name....
declare @DBname varchar(255)
select @DBname = 'db2'
select accoID from @DBname.dbo.acco
If I type db2.dbo.acco it works perfect. However, when I use the variable I get the error:
Incorrect syntax near '.'
Any ideas are greatly appreciated...
Regards,
Mike
Simple question...
I have a stored procedure-- I want to be able to change the database I copy data from and to. Below is a simple example... I cannot figure out why I am unable to use a variable for the database name....
declare @DBname varchar(255)
select @DBname = 'db2'
select accoID from @DBname.dbo.acco
If I type db2.dbo.acco it works perfect. However, when I use the variable I get the error:
Incorrect syntax near '.'
Any ideas are greatly appreciated...
Regards,
Mike