Checking uptime of all SQL Instances . I can extract details for the present SQL SSMS where I'm running. Need for all the available SQL Instances.

  • HI Guys

    The below script goes well with me to check SQL Uptime of the Presrnt SQLInstances. I needed to run and get the details across all running SQL Instances.

    SET NOCOUNT ON

    DECLARE @crdate DATETIME,

    @days varchar(3),

    @hr VARCHAR(50),

    @min-2 VARCHAR(5)

    SELECT @crdate=crdate FROM sysdatabases WHERE NAME='tempdb'

    SET @min-2 = DATEDIFF (mi,@crdate,GETDATE())

    SET @days= @min-2/1440

    SET @hr = (@min/60) - (@days * 24)

    SET @min-2= @min-2 - ( (@hr + (@days*24)) * 60)

    PRINT 'SQL Server "' + CONVERT(VARCHAR(20),SERVERPROPERTY('SERVERNAME'))+'" is Online for the past '

    +@days + ' days & '

    +@hr+' hours & '

    +@min+' minutes'

    IF NOT EXISTS (SELECT 1 FROM master.sys.sysprocesses WHERE program_name = N'SQLAgent - Generic Refresher')

    BEGIN

    PRINT 'SQL Server is running but SQL Server Agent running'

    END

    ELSE

    BEGIN

    PRINT 'SQL Server and SQL Server Agent both are running'

    END

    Thanks.

Viewing 0 posts

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