Posted: Thu Jan 26, 2006 4:26 pm Post subject: Update by cursor
I can use "WHERE CURRENT of Cursor_Name" when rows are selected form a single table. It wouldn't work if the FROM clause of the SELECT statement contains more than one table. But I need join another table to get the "Status" to determine if update should be applied. Is there a work around?
"DECLARE SELCUR CURSOR FOR",
"SELECT A.COL1, A.COL2, A.COL3, B.STATUS",
"FROM TABLE A, TABLE B",
"WHERE A.KEY1 = B.KEY1 AND A.KEY2 = B.KEY2 AND A.KEY3 = B.KEY3",
"AND B.STATUS IN ('X','Y')",
"FOR UPDATE OF COL1, COL2, COL3"
"OPEN SELCUR"
Do until SqlCode = 100
"FETCH SELCUR INTO :DATA1, :DATA2, :DATA3, :STATUS"
"UPDATE TABLEA SET COL1 = :NEWDATA1, COL2 = :NEWDATA2, COL3 = :NEWDATA3",
"WHERE CURRENT OF SELCUR"
/* Insert rows into table c only if stauts = 'Y' */
If Stauts = 'Y' then "INSERT INTO TABLEC VALUES (:DATA1, :NEWDATA1,.....)
End
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum