Find the Server Name or Instance Name using T-SQL

The following instructions are supposed to return the same results,  but sometimes the results can be different. The reason is that SERVERPROPERTY automatically reports changes in the network name of the computer, while @@SERVERNAME don’t.
SELECT CONVERT(sysname, SERVERPROPERTY(N’servername’))

GO

SELECT @@SERVERNAME

When they are run on the default instance they return just the server name, but when run over a named instance they return the server name in the following format: servername/instancename.

,

No comments yet.

Leave a Reply

*