I need to have a query like below to run to select all the fields from different databases that each database have a table named 'table1'
select * from test...table1
select * from test1..table1
I have the following code sample:
declare @.dbname varchar(50)
set @.dbname='test'
select @.dbname
select * from @.dbname..table1
However I received the error messge when I ran this code. Can anyone help to resolve this?
Thank you!
Hi
One way of doing this is to build the query dynamically and use the Exec, as shown in the example below:
Declare @.xQuery varchar(1000)
Select @.xQuery = 'Select * from test..table1'
Exec(@.xQuery)
Select @.xQuery = 'Select * from test1..table1'
Exec(@.xQuery)
Best regards
Georg
www.l4ndash.com - Log4Net Dashboard / Log4Net Viewer
No comments:
Post a Comment