Archive

Posts Tagged ‘server name’

Using Built-in Configuration Functions – @@SERVERNAME, @@SERVICENAME

24.05.2011 No comments

You can user the built-in configuration function @@SERVERNAME to get the server name using TSQL.

It can be used as below:

SELECT @@SERVERNAME AS 'Server Name'

Result Set:

Server Name

——————————————————————————————————————————–

VGAJJAR2SQL01

 

(1 row(s) affected)

 

@@SERVERNAME returns the Server Name Instance Name, To return only the instance name, we can use @@SERVICENAME function.

@@SERVICENAME returns the current instance name, for a default instance it will return 'MSSQLServer'.

 

SELECT @@SERVICENAME AS 'Service Name'

Result Set:

Service Name

——————————————————————————————————————————–

SQL01

 

(1 row(s) affected)

If you run the same query on a Default Instance of SQL Server, the result set will be:

Service Name

——————————————————————————————————————————–

MSSQLSERVER

 

(1 row(s) affected)

 

Hope This Helps!

Vishal