declare @cSecondDb as Varchar(100) DECLARE @sql nvarchar(200) declare @Category as Varchar(25); set @Category = '1009F' set @cSecondDb = 'SecondSQLDatabase' SET @sql = 'select * from '+@cSecondDb+'..mytable where Category = @Category' EXEC sp_executesql @sql, N'@Category varchar(25)', @Category = @Category>Hi,
>use [FirstSQLDatabase] >go >select * from SecondSQLDatabase..mytable where 1=1 >>
>use [FirstSQLDatabase] >go >declare @cSecondDb as Varchar(100) >set @cSecondDb = 'SecondSQLDatabase' >select * from @cSecondDb..mytable where 1=1 -- this is the line that causes the syntax error. >>