April 10, 2019 at 2:36 pm
Hi,
i need this query to run against 20 instances from main server that have linked server to those 20 instances.i want to change the [@server] to the right instance via cursor and make the SELECT statement to work.
how can i write the query accordingly?
THX
declare @server varchar(50)
set @server = 'servername\instnacename'
SELECT N'<TD>' + ISNULL( + '<p class="datarows">' + (SELECT CONVERT(NVARCHAR(MAX),column_name) from [@server].db_name.dbo.table_name),'<p class="datarowserror">Not Avail') + N'</p></TD>'
April 12, 2019 at 1:31 pm
Personally, I wouldn't do this through T-SQL. I'd use Powershell. Here's an example.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
April 12, 2019 at 2:13 pm
You could query sys.sysservers in master to get the linked servers, then with a cursor you can loop through them.
April 12, 2019 at 6:01 pm
Personally, I wouldn't do this through T-SQL. I'd use Powershell. Here's an example.
And then scream as the Network folks draw and quarter you for screwing up internal security.
Lordy, Grant... did you move from subs to grey-hounds???
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy