views:

69

answers:

3
+1  Q: 

Supress SQL Output

When running a SQL query with output to text we typically get back output like this.

AssetID              Occurs
-------------------- -----------

(0 row(s) affected)

Since I am doing thousands of select statements to audit data in my table is there a way to suppress this output on SQL server?

+1  A: 

Prefix the query with:

set nocount on

to suppress to rowcount messages. You can disable column headers in SSMS, under Tools -> Options - > Query Results -> Results To Text.

As for the rows themselves, you could suppress them by adding a clause like where 1=0, but then I wonder why you select them in the first place.

Andomar
That turns the count off and gives output like this. AssetID Occurs -------------------- -----------
Mike
+2  A: 

If you want to suppress the whole block you've shown then you'd need to do:

SET NOCOUNT ON

...

IF EXISTS(SELECT AssetId FROM Table)
BEGIN
    SELECT AssetId, Occurs FROM Table
END
David M
Thanks.. So basically suppress output until we find the count were are looking for.Cheers
Mike
`IF EXISTS` would be a better choice here. It's not necessary to get the whole count just to check if it's > 0.
Aaronaught
@Aaronaught - thank, of course you're right. +1 and I'll edit.
David M
A: 

Some developers commonly include SET NOCOUNT ON in all stored procedures, unless they really do want to know how many records were changes.

DOK