Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

@@servername returns NULL

Status
Not open for further replies.

NathanGriffiths

Programmer
May 14, 2001
213
0
0
NZ
When I query the global variable which is supposed to contain the name of the local SQL Server e.g.

SELECT @@servername

it returns NULL instead of the server name. This is supposed to be set during installation.

According to BOL I should be able to change the local server name using

sp_addserver '<servername>','local'

However, when I do this I get an error message saying '<servername>' already exists. Anyone know what's going on?

thanks,

Nathan
 
I have had this problem where a server had somehow 'lost' its @@servername, but I found that running 'sp_addserver 'pro26', local' and restarting SQL server resolved the problem
 
If you run
'use master
select * from sysservers'

you will find that athere is a row with your servername probably with an srvid of 1. This swould have been created by a previously run sp_addserver.
You need to use sp_dropserver '<servername>'to drop that first. Then run sp_addserver '<servername>','local'
to add. This time the entry will have a srvid of 0. This means local. Then SELECT @@servername will give you correct value.

Hope it helps
Tony Khela
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top