views:

12

answers:

1

If I run a simple query in SQL Query Analyzer, like:

SELECT * FROM TableName

the Messages pane always produces a message like:

(30 row(s) affected)

If I run a stored procedure with many statements, the messages are useless because there's no indication of what each one relates to.

So firstly: Is there a way to customise the default messages on a per-query basis?

E.g. I'd like a specific query to produce a message like:

TableName query produced [numRowsAffected] results.

replacing [numRowsAffected] with the number that would have appeared in the default message.

Secondly, is there a way to suppress the default messages on a per-query basis?

E.g. I have a local variable of type TABLE, used in several statements.

I don't want any message to appear for statements where I'm just deleting data from that variable before re-using it.

I'm seeking solutions that work in SQL Server 8.0.

+2  A: 

You can use SET NOCOUNT ON to suppress the rowcounts being returned. Just put that at the top of your stored procedure.

As for returning a custom message, if you really had a need for that, you'd need to manually print it out yourself from within the sproc:

e.g. example

SET NOCOUNT ON
SELECT TOP 5 TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
PRINT 'MyExampleQuery produced ' + CAST(@@RowCount AS VARCHAR(20)) + ' results'
AdaTheDev
Perfect. Thanks.
Scott Leis