Pages

Friday, March 11, 2011

SELECT @@SERVERNAME Showing Null

SELECT @@SERVERNAME
With multiple instances of SQL Server installed, @@SERVERNAME returns the following local server name information if the local server name has not been changed since setup.
Instance
Server information
Default instance
'servername'
Named instance
'servername\instancename'
failover clustered instance - default instance
'virtualservername'
failover clustered instance - named instance
'virtualservername\instancename'

It may happen so that when you run SELECT @@SERVERNAME, it may return NULL value.

Whenever you change the Network Name of Server Name, @@SERVERNAME does not report such changes. @@SERVERNAME reports changes made to the local server name using the sp_addserver or sp_dropserver stored procedure.

To make SELECT @@SERVERNAME reflect the new changed Network Name perform the below task.

USE master
GO
EXEC sp_dropserver 'OLDSERVERNAME'
GO
EXEC SP_addserver 'NEWNETWORKNAME','LOCAL'
GO

Once done please Stop and Start the SQL Services and then Query SELECT @@SERVERNAME. Bingo You are Done. Now you should be getting the New Network Name.

1 comment: