all groups > sql server programming > february 2005 >
You're in the

sql server programming

group:

sql mail


sql mail chinna jambu via SQLMonster.com
2/20/2005 8:33:28 PM
sql server programming: i created a query which insert rows in to another table, and send mail to
the recepient using sql mail task.
the work flow Success is sending mail even 0 rows inserted into the table.

Is their any way i can send mail only if row insert in to table?

--
RE: sql mail John Bell
2/22/2005 12:09:01 AM
Hi

If you encapsulate your insert statement in a stored procedure then after
the insert statement you should check @@ERROR and also saving the value of
@@ROWCOUNT. You can see if the insert statement returned any rows.

CREATE PROCEDURE MyInsert
AS
BEGIN
DECLARE @stat int, @row_count int

INSERT INTO MyTable (col1...) VALUES (... )
SELECT @stat = @@ERROR, @row_count = @@ROWCOUNT
IF @stat <> 0 RETURN @stat

IF @row_count > 0


[quoted text, click to view]
RE: sql mail John Bell
2/22/2005 12:17:10 AM
Hi

Seems that this posted before I finished typing...


CREATE PROCEDURE MyInsert
AS
BEGIN
DECLARE @stat int, @row_count int

INSERT INTO MyTable (col1...) VALUES (... )
SELECT @stat = @@ERROR, @row_count = @@ROWCOUNT
IF @stat <> 0 RETURN @stat

IF @row_count > 0
EXEC @stat = xp_sendmail .....

RETURN @stat
END

[quoted text, click to view]
AddThis Social Bookmark Button