Script result display in messages not in Grid

  • hi,

    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

    go

    This script working fine and display result in message type.

    I want display the result in Grid, Can anyone have this query result in store in Grid? please give me.

    Thanks

    ananda

  • Not sure I understand.

    Use SELECT instead of PRINT?

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • yes, It is correct & working fine

    Thanks

    ananda

  • Just make sure you have this icon selected. For some reason, it sometimes changes. See attached image for details.

    EDIT --- NM, looks like I misunderstood your question.

  • Hi, see this above script It is clearaly mention "Print command"

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

    If using print command in sql statement, result set disply in messages not in grid format, even this ICON is selected or not selected result will not dispaly in Grid.

  • Right, so like Phil said:

    replace the PRINT with SELECT

    IE:

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

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

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