Link to home
Start Free TrialLog in
Avatar of hennessym
hennessym

asked on

"SET NOCOUNT ON" is not working in my stored procedure

I have a script that e-mails me if new records have been added to a table within the past 24 hours.  The body of the e-mail indicates when the most recently added record was inserted into the table:

USE [Cyfast_Stockaid]
GO
/****** Object:  StoredProcedure [dbo].[NewDataCheck]    Script Date: 06/25/2008 13:04:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER procedure [dbo].[NewDataCheck] AS

SET NOCOUNT ON

if not exists (select top 1 * from mydb.dbo.mytable where datediff(ss,UpdateDate,getdate()) < 86400)      
      begin            
            EXEC msdb.dbo.sp_send_dbmail
            @recipients = 'myemail@mail.com',                         
            @subject = 'Database alert: No new Data within past 24 hours!',
            @query = 'select top 1 ''LastUpdated: '' + CONVERT(VARCHAR(10), UpdateDate, 101) from mydb.dbo.mytable order by UpdateDate desc',
            @importance = 'high';
      end

This works as designed except that I see the number of records affected in the body of the e-mail, seemingly indicating that SET NOCOUNT ON is not working:

-----------------------
LastUpdated: 06/20/2008

(1 rows affected)

Does anyone know how to solve this?

Thanks in advance.

ASKER CERTIFIED SOLUTION
Avatar of jgv
jgv

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hennessym
hennessym

ASKER

Thanks - that's exactly what I needed.