I need help in modifying this script

  • I have this script, I want to use the case or if command instead of print. The print is not displaying on result , it is displaying on message. Please help me so that I will get the output on Result in query analyzer.

    --- to find the server uptime

    SET NOCOUNT ON

    DECLARE @crdate DATETIME, @hr VARCHAR(50), @min-2 VARCHAR(5)

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

    SELECT @hr=(DATEDIFF ( mi, @crdate,GETDATE()))/60

    IF ((DATEDIFF ( mi, @crdate,GETDATE()))/60)=0

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

    ELSE

    SELECT @min-2=(DATEDIFF ( mi, @crdate,GETDATE()))-((DATEDIFF( mi, @crdate,GETDATE()))/60)*60

    PRINT 'SQL Server "' + CONVERT(VARCHAR(20),SERVERPROPERTY('SERVERNAME'))+'" is Online for the past '+@hr+' hours & '+@min+' minutes'

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

    BEGIN

    PRINT 'SQL Server is running but SQL Server Agent <<NOT>> running'

    END

    ELSE BEGIN

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

    END

  • Hi

    Can you explain clearly what you are trying to say,the above query runs fine for me it gives correct result

    Thanks

    Parthi

    Thanks
    Parthi

  • I know it does give a correct result, I am trying to turn this into store procedure for daily monitoring and when I run the sp the result is printing on message instead of Result pane.

  • Change "print" to "select".

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Here is the altered script.

    SET NOCOUNT ON

    DECLARE @crdate DATETIME, @hr VARCHAR(50), @min-2 VARCHAR(5)

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

    SELECT @hr=(DATEDIFF ( mi, @crdate,GETDATE()))/60

    IF ((DATEDIFF ( mi, @crdate,GETDATE()))/60)=0

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

    ELSE

    SELECT @min-2=(DATEDIFF ( mi, @crdate,GETDATE()))-((DATEDIFF( mi, @crdate,GETDATE()))/60)*60

    select 'SQL Server "' + CONVERT(VARCHAR(20),SERVERPROPERTY('SERVERNAME'))+'" is Online for the past '+@hr+' hours & '+@min+' minutes'

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

    BEGIN

    PRINT 'SQL Server is running but SQL Server Agent <<NOT>> running'

    END

    ELSE BEGIN

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

    END

  • Thank you so much!

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

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