I have say a couple of statements that gets values from a database e.g:
declare @intValue = 0;
use [databaseA]
select @intValue = @intValue + columnA from tableA where id = 5;
The above statement has to be made multi database so I would like to do something like:
declare @intValue = 0;
use [databaseA]
select @intValue = @intValue + columnA from tableA where id = 5;
use [databaseB]
select @intValue = @intValue + columnA from tableA where id = 5;
Now is there a way to simplify the above query without copying and pasting several times if i have multiple databases WITHOUT using dynamic SQL?
I'm hoping for something with a cursor or something that might work out?
It might be something like
for each database in DatabaseList
use [database]
select **** statements;
end for
I'm not sure if it's possible without using dynamic SQL.