@@Servername returns NULL

  • Hi,

    SELECT @@Servername  is returning NULL for one of my databases 

    but if i say:

    SELECT   CONVERT(char(20), SERVERPROPERTY('servername'))

    its giving the servername correctly.

    Problem is that we are using SELECT @@Servername at a number of places in our SPs and hence all of them are breaking.

    Please advise how to resolve this.

    Regards,

    RSingh

  • server name is stored in sysdatabases. How do you connect to get @@servername? Are you on a server machine with sysadmin rights? if something happened to your server name in this case you may want to execute sp_dropserver and sp_addserver specifying Local as a server, similar to when you are changing a server name.

    @@Servername article in BOL says:

    ".....Although the @@SERVERNAME function and the SERVERNAME property of SERVERPROPERTY function may return strings with similar formats, the information can be different. The SERVERNAME property automatically reports changes in the network name of the computer.

    In contrast, @@SERVERNAME does not report such changes. @@SERVERNAME reports changes made to the local server name using the sp_addserver or sp_dropserver stored procedure...."

    So it could happen that they changed the name of the server and that is why you have problems with @@servername.  Do sp_addserver.

    Regards,Yelena Varsha

  • Thanks Yelena for the reply.

    But i forgot to mention that i had alread tried the following:

    a) sp_dropserver
    b) sp_addserver 'DB02', local
    c) restart sql server
     
    but this also didn't help
     
    Regards,
    Rsingh
  • [snip]

    Posting created 2 replies, did not post twice this time...

    Andy

     

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply