Display Computer Name

  • Hi Gud AM to all are there any command to display the computer name of a server other than @@servername? I can't use serverproperty('servername') because it is not recognized by sql server version 7 (no sp). The reason i ask for this is because i have a task to backup serveral databases in different servers to a single remote server location. I made a link server for all of the servers and made a script to run only 1 sql command and instruct the servers to backup the databases to that single remote location. My problem is that I need to differentiate the backup file for each server databases.

    Example:

    I have Servers A,B,C each of them has db1,db2,db3 when they are backup in the remote location i want the filename to be

    db1_A_db_YYYYMMDDHHMM.BAK

    db1_B_db_YYYYMMDDHHMM.BAK

    Thats the reason i need to include the computer name. Thank you very much...

    "-=Still Learning=-"

    Lester Policarpio

  • Does SQL 7 include the procs for

    * Registry access

    * OLE Automation?

    You could go either of those methods.

    Or, use xp_cmdshell to run "set computername" and parse the results.

    Or, create a table, perhaps in master or in a specific utility db on each server, that contains the name of the server.

  • Thanks for the quick response this is what i did

    --= Use Northwind Database for testing

    Use Northwind

    GO

    --= Condition if the table doesn't exists

    IF NOT EXISTS (select name from sysobjects where xtype = 'U' and name = 'Test_Table_Hostname')

    --= Create table Table_Hostname

    BEGIN

    CREATE TABLE Test_Table_Hostname (hostname varchar(100))

    END

    --= Insert in the table result of the command xp_cmdshell 'hostname'

    INSERT INTO Northwind..Test_Table_Hostname exec master..xp_cmdshell 'hostname'

    --= Test QUery

    select * from Northwind..Test_Table_Hostname

    --=Delete Table

    DROP TABLE Test_Table_Hostname

    "-=Still Learning=-"

    Lester Policarpio

Viewing 3 posts - 1 through 2 (of 2 total)

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