Mar 10, 2005 #1 NSMan Technical User Joined Aug 26, 2004 Messages 72 Location US How can I do this? declare @database varchar(20) set @database='img000029' select * from @database.dbo.imgs
How can I do this? declare @database varchar(20) set @database='img000029' select * from @database.dbo.imgs
Mar 10, 2005 #2 gmmastros Programmer Joined Feb 15, 2005 Messages 14,912 Location US You can use dynamic sql to do this. Dynamic SQL is best avoided if possible. Code: declare @database varchar(20) Declare @SQL VarChar(8000) set @database='img000029' Set @SQL = 'select * from [' + @database + '].dbo.imgs' Exec (@SQL) -George Strong and bitter words indicate a weak cause. - Fortune cookie wisdom Upvote 0 Downvote
You can use dynamic sql to do this. Dynamic SQL is best avoided if possible. Code: declare @database varchar(20) Declare @SQL VarChar(8000) set @database='img000029' Set @SQL = 'select * from [' + @database + '].dbo.imgs' Exec (@SQL) -George Strong and bitter words indicate a weak cause. - Fortune cookie wisdom