SQL Gurus, a little T-SQL help

Discussion in 'OT Technology' started by Supernaut, Nov 21, 2007.

  1. Supernaut

    Supernaut New Member

    Joined:
    May 20, 2003
    Messages:
    8,047
    Likes Received:
    0
    Here's my query:

    Code:
    PRINT N'Checking for open connections to GoldTest database...'
    IF EXISTS (SELECT SPID,
    
              STATUS,
    
              PROGRAM_NAME,
    
           LOGINAME=RTRIM(LOGINAME),
    
              HOSTNAME,
    
              CMD
    
    FROM  MASTER.DBO.SYSPROCESSES
    WHERE DB_NAME(DBID) = 'GoldTest' AND DBID != 0)
    BEGIN
    PRINT N'Open connections exist on database GoldTest.'
    END
    I'd like to return the hostname of the computer(s) with open connections in the PRINT message at the end of the query. Possible?
     

Share This Page