October 23, 2008 at 6:33 pm
Hi,
I am trying to build the following query:
declare @s-2 nvarchar(500)
declare @Dbname nvarchar(50)
declare @dbs table (Dbname sysname)
insert into @dbs select name from master.dbo.sysdatabases (nolock) where [name] LIKE 'MyDB__'
set @Dbname = (select min(Dbname) from @dbs)
while @Dbname is not null
begin
SELECT @s-2= 'select CompanyName from [@Dbname].dbo.company (nolock)'
EXEC sp_executesql @s-2, N'@Dbname nvarchar(50)', @Dbname=@Dbname
set @Dbname = (select min(Dbname) from @dbs where Dbname > @Dbname)
end
but it returns this error:
Msg 208, Level 16, State 1, Line 1
Invalid object name '@Dbname.dbo.company'.
Any ideas?
Thanks.
P.S.: Sorry, I've posted this in SQL 2000 forum first by mistake.
October 23, 2008 at 8:21 pm
Duplicate Post. Please do not cross-post.
Please direct all replies to http://www.sqlservercentral.com/Forums/Topic590891-8-1.aspx
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply