Subject Re: [firebird-support] Getting number of records affected ...
Author Lucas Franzen
Anand,


Anand schrieb:

> I am trying to write a stored procedure that will attempt an
> Update ...
> statement first. Then it should check for the number of records
> affected by
> the Update statement, and if the number of records affected are
> zero, it
> should issue an Insert... statement.

> How do I find out the number of records affected by an action
> query?

with FB1.5 you can use ROW_COUNT,

Example:

UPDATE MYTABLE SET MYFIELD = 0 WHERE MYCONSITION = 'Blabla'

IF ( ROW_COUNT ) = 0 THEN
BEGIN
INSERT INTO MYTABLE ...
END



If you use FB prior to 1.5 you can do sth. like:


...
declare variable IS_RECORD_THERE integer;
...

SELECT 0 FROM RDB$DATABASE
WHERE NOT EXISTS ( <update_condition> )
INTO :IS_RECORD_THERE;

IF ( IS_RECORD_THERE = 0 ) THEN
BEGIN
/* do your insert */
END



Luc.