T-SQL to find Remote Server Name of the linked server | SansSQL

Friday, April 22, 2022

T-SQL to find Remote Server Name of the linked server

At times it happens that you might have named a linked server with a friendly name that the actual server name. As the time flies and people change in the team, it will become difficult to identify how or to where this is linked.  You can find the information using the sp_linkedservers stored procedure but what if the linked server configured uses a entirely different DNS name than the actual server? The below query helps to get the Remote Server Name with few other details when run against a linked server.  

DECLARE @linkedServerName varchar(100), @sql varchar(max)
SET @linkedServerName='Your Linked Server Name'
SET @sql = CONCAT('SELECT * FROM OPENQUERY([',@linkedServerName , '], 
''SELECT ''''',@linkedServerName,''''' AS LinkedServerName, 
@@SERVERNAME AS RemoteServerName, SUSER_SNAME() AS ConnectedWith, DB_NAME() AS DefaultDB'')')
EXEC (@sql)

1 comment:

LasseNielsen said...

Thanks to https://wow24-7.io/blog/the-best-5-live-chat-etiquette-tips-for-making-customer-support-outsourcing-effective, the company has saved an enormous amount of time since they don't handle support tickets anymore. What the client liked the most about them is their ability to grow new leads and suggest changes that can make the company more dynamic. Customers can expect a responsible team.

Post a Comment