Server name

  • I can get the database name from DB_Name() BUT

    how can I get the Server name?

    Thanks,

    Phil

  • Try @@ServerName.

  • I will try that.  Thanks

    BUT

    I was able to get it with this as well 

    DECLARE @DBServer nvarchar(50)

    SELECT @DBServer = name FROM sys.servers

    Again thanks for your help.

    Phil

     

     

  • Don't be fooled, neither get used to it. Go ahead and create some linked servers, or connect to other instances and so on and run the the same query.

     

  • Camilo is right. That seems to work fine in your situation because you apparently don't have any linked servers.

    Generally, you have to add

    Where server_id = 0

    But in any case select @@servername is more elegant

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

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