Subject SQL needs to be reviewd and some questions:
Author william_yuwei
Hi, All

1) I have following SQL code in one of my stored procedure:

update DIVISION set
LOCKED = :PostBy
where ID = :DivisionID and LOCKED is null;

if (ROW_COUNT <= 0) then
begin
Result = -3; /* Failed to get invoice number. */
exit;
end

LastInvoiceNo = null;
select LASTINVOICENO from DIVISION
where ID = :DivisionID and LOCKED = :PostBy
into :LastInvoiceNo;

LastInvoiceNo = LastInvoiceNo + 1;

/******** UNLOCK Division and UPDATE its LastInvoiceNo ********/
update DIVISION set
LASTINVOICENO = :LastInvoiceNo,
LOCKED = null
where ID = :DivisionID and LOCKED = :PostBy;

Q: Could I use SELECT UPDATE LOCK syntax to replace the above code? if
so how to do it and how to do unlocking?

2)Q: How to use "WHEN SQLCODE xxxx DO BEGIN ... END", Do I have to put
each WHEN after update/insert/delete statement, or just one WHEN
statement at the end of the procedure(more simailiar with the Delphi
try ... except ... end;)?

3)Q: Where can I get all the SQLCODE value, e.g. what's the value for
Deadlock sqlcode, any doc I can take a look at?

Thanks

Best Regards,

William