I am trying to create a query that will be executed once for a specific table in a specific database in each server in sys.server.
For each server.database.dbo.table I want to know the contents.
So what I need is something like:
declare @numrows int = (select count(*) from sys.servers)
declare @i int = 1
while @i <= @numrows
BEGIN
declare @servername varchar(max) = (select servernaam from #servers where rij = @i)
select * from @servername.DATABASE.DBO.TABLE
set @i = @i+1
END
However, the @servername in @servername.DATABASE.DBO.TABLE does not seem to work.
Suggestions? Thanks for thinking with me.