Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 only send email if there are results

Author  Topic 

bugulgad
Starting Member

21 Posts

Posted - 2008-12-16 : 15:50:28
I have a data validation query that I only want to email if there are results.

I figure I will use sp_send_dbmail to send the email of the results....but I don't know how to filter the event to only happen if there are some results.

I think there is a function for this, but I can't find what I am looking for.

hanbingl
Aged Yak Warrior

652 Posts

Posted - 2008-12-16 : 16:01:55
IF EXISTS(YOUR QUERY)
BEGIN
SP_SEND_DBMAIL
END
Go to Top of Page

bugulgad
Starting Member

21 Posts

Posted - 2008-12-16 : 16:26:01
I was thinking there would be a rowcount function to test on > 0
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-16 : 16:29:45
There is: @@ROWCOUNT. But I would go with IF EXISTS solution as mentioned already.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

bugulgad
Starting Member

21 Posts

Posted - 2008-12-16 : 16:45:53
thanks all. I went with the IF EXISTS solution, worked great
Go to Top of Page
   

- Advertisement -