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.
Advertisements

2 thoughts on “Select @@ServerName Showing Null

  1. Hi,

    I had tweeked the instance network name by using sp_addserver but it is not getting depicted in the Enterprise Manager. Let me know the reason for the same.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s