This variable returns a nvarchar value that represents the name of the local server.
If the current instance is a default instance, it will return “servername”. If the instance is a named instance, then it will return “servername\instancename”.
I would prefer SERVERPROPERTY(‘servername’) over this global variable. The SERVERNAME property automatically reports changes in the network name of the computer. But, @@SERVERNAME does not report such changes automatically unless the changes are made to the local server name using the sp_addserver or sp_dropserver stored procedures.
This variable returns a nvarchar value that represents the service name of SQL Server. If the current instance is a named instance, it will return the instance name else if its a default, then it reutrns “MSSQLSERVER”
This variable returns the name of the remote SQL Server database server as it appears in the login record.
Since am currently using SQL Server 2016, this feature returns NULL value, however , in earlier version it was returning the server name from where the procedure is being called. There is an example of how it was working in MS official documentation: https://docs.microsoft.com/en-us/sql/t-sql/functions/remserver-transact-sql?view=sql-server-ver15
This feature has been deprecated, hence its not really advisable to use in future development and also recommend to find a better way to replace in existing codes.
Honestly, I was not really able to find a good alternative for this feature and also asked this question in MS Q&A looking for an answer. Unfortunately, there are not much help on this.
If you enjoyed this blog post, feel free to share it with your friends!