none
SQL Server Management Studio - Clearing the output in Results Grid

    Question

  • Hi,

    Is there a way in SQL Server Management Studio (2008 or 2012) to clear the output that may be there in results window? For example, if I run the following queries, I will get two grids or combined in output in (Text Mode):

    select getdate() 
    go

    select getdate()
    go

    Then I would get something like this:

    -----------------------

    2012-09-14 11:51:16.710

    (1 row(s) affected)

     

    -----------------------

    2012-09-14 11:51:16.723

    (1 row(s) affected)

    Is there a way to clear result that is already there so that output comes like this? So far I have not been able to figure out how to do this. Only option I see to clear all results after execution.

    2012-09-14 11:51:16.723

    (1 row(s) affected)

    Thanks,

    Vijay

    Friday, September 14, 2012 3:54 PM

Answers

  • Hi Vijay, if I understand the question correctly, there is no way to combine result sets in the output or only display the final set of results.  If the set of statements that you execute produces multiple result sets, you will see all of the different result sets in the results pane.  To get a single result set, you can highlight the individual statement and execute the highlighted query.

    Thanks,
    Sam Lester (MSFT)


    My Blog

    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.

    Friday, September 14, 2012 4:45 PM
  • Why do you want to run this in SSMS?   Why not an independent tool? 

    I would think that you could easily create a simple client using Microsoft Access that will run your select into a grid.   Using Access you can clear and refresh the grid. Then you control the looping and delay in Access instead of T-SQL. 

    Or, perhaps as you were thinking, you could skip Access or some other tool and simply run a CMD file with SQLCMD that selects the query to the screen, delays, then runs clear screen and loops back to the top. 

    In either case, much like you describe, you are keeping no history.  It is just a snapshot of the moment. 

    FWIW,
    RLF

    Tuesday, September 18, 2012 8:16 PM

All replies

  • Hi Vijay, if I understand the question correctly, there is no way to combine result sets in the output or only display the final set of results.  If the set of statements that you execute produces multiple result sets, you will see all of the different result sets in the results pane.  To get a single result set, you can highlight the individual statement and execute the highlighted query.

    Thanks,
    Sam Lester (MSFT)


    My Blog

    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you. This can be beneficial to other community members reading the thread.

    Friday, September 14, 2012 4:45 PM
  • The reason I'm asking is this becausing I would like to run set of queries over pre-defined interval  - something like this

    while (1=1)
    Begin
        SET NOCOUNT ON;
        select 'NoWatingTasks: ' + Cast(count(*) as varchar) NoWatingTask from sys.dm_os_waiting_tasks
        Union All
        select 'NoSessions: ' + Cast(count(*) as varchar) NoSessions from sys.dm_exec_sessions; 
        raiserror('',0,1) with nowait --to flush the buffer
        waitfor delay '00:00:10'
    end

    If don't clear the output then Mgmt Studio just keeps on appending. Does SQL Server 2012 provide an option (or command to be invoked) to achive this. Or is there other way to do this (SQLCmd comes to mind but it is very cumbersome to use)? Is there a better way to do this? This almost works perfectly for me only if I could clear the output!

    Tuesday, September 18, 2012 6:16 PM
  • Why do you want to run this in SSMS?   Why not an independent tool? 

    I would think that you could easily create a simple client using Microsoft Access that will run your select into a grid.   Using Access you can clear and refresh the grid. Then you control the looping and delay in Access instead of T-SQL. 

    Or, perhaps as you were thinking, you could skip Access or some other tool and simply run a CMD file with SQLCMD that selects the query to the screen, delays, then runs clear screen and loops back to the top. 

    In either case, much like you describe, you are keeping no history.  It is just a snapshot of the moment. 

    FWIW,
    RLF

    Tuesday, September 18, 2012 8:16 PM