Identifying the local server?

  • Without using @@SERVERNAME, I need to find the 'local server' when connected to an instance. I would like to use sysservers, but am not sure of the exact criteria to use. Can I use isremote of 0 (zero)? Or where srvid is equal to 0 (zero)?

  • I thought you'd just use: select srvname from master.dbo.sysservers

  • That's not enough when there are linked servers (or remote servers - not sure what the difference is, since we create linked server (sp_addlinkedserver) between two databases on the same instance). Anyway, I was using the criteria where srvproduct = 'SQL Server' and srvname = datasource, but I got back multipe rows - when I expected only one row. I was wondering if isremote and/or srvid could be used in addition to my existing criteria. The problem is I am not sure if these are reliable?

  • I think you are right by using srvid = 0 and isremote = 0 to identify the local server.

    Why you can't use @@servername?

  • So will the following select give me the 'local server':

    select srvname

    from master.dbo.sysservers

    where srvproduct = 'SQL Server'

    and srvname = datasource

    and srvid = 0

    and isremote = 0

    Can I remove some of my criteria, or use only the srvid or the isremote (or do I need to use both)? Will these be reliable through the life of this instance? I just want to be 100% sure this method will work.

    Thanks!

  • I think srvid = 0 and isremote = 0 are sufficient.

  • Thanks. I will use srvid and isremote to retrieve the local server.

Viewing 7 posts - 1 through 6 (of 6 total)

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