Je moet dynamische sql gebruiken:
declare @numrows int = (select count(*) from sys.servers)
declare @i int = 1
declare @Sql(1000)
declare @servername varchar(max)
while @i <= @numrows
BEGIN
select @servername = servernaam
from #servers where rij = @i
set @Sql = 'select * from '[email protected]+'.DATABASE.DBO.TABLE'
exec(@Sql)
set @i = @i+1
END
Hier is meer informatie over exec.