Re: Help: update record if existed, else insert it
Posted in 1996
In article <52n6ik$2fv@voyager.iii.org.tw>,
c811052@bsdpc1.iii.org.tw (Chih-Cherng Chin) wrote:
Use the SQLCA record to find out whether an UPDATE actually
updated records. e.g
UPDATE table
SET ....
IF SQLCA.SQLERRD[3] = 0 THEN
INSERT INTO table VALUES (....)
END IF
Rudy
>Hi all,
>
>Being new to SPL, and wanting to implement a SP to log hits, I'm having
>problems writing it. I want to do the following:
>
>1. if the corresponding record exists, update its column,
>2. if not, insert a new record.
>
>Originally, I thought about doing it this way:
>
>1. Try to update the record, whether it exists or not,
>2. if the update failed, use the exception to insert a new record.
>
>But it turns out that the failed update is not considered as a
>error, so I can't do that. I think there are many problems similar
>to this, so please share your experience. Thanks in advance.
>
>Chih-Cherng Chin
>elmo@iii.org.tw