I have a situation in which I am initially inserting a set of records into a table (tableA) and then, using a series of updates I need to update a field (tableA.field1) in the same table which was not populated during the initial insert. I am plannining on using the For Update Of and Where Current Of clauses in a cursor in order to update these fields.
My problem is that the fields I am updating are being populated based on individual subselects of data from another table (tableB), and the data to populate tableA.field1 could be in either of 2 records in tableB. I want to try for the data (tableB.field2) from one record in tableB based on a criterion in another field in tableB (tableB.field3). If there is data in tableB.field2 for that record, that is great, I update tableA.field1 with that data, if tableB.field2 is empty, I want to requery tableB using a different value for my tableB.field3 criterion.
Example (I want to duplicate this logic and I am wondering if I can do it all inside of my cursor):
set tableA.field1 = (Select tableB.field2 from tableB where tableB.field3 ='abc')
If tableA.field1 is null Then
Set tableA.field1 = (Select tableB.field2 from tableB where tableB.field3 ='xyz')
I would like to be able to do this while I am sitting on an individual record in my update cursor, but I don't know if this is possible.
Any help would be appreciated.
My problem is that the fields I am updating are being populated based on individual subselects of data from another table (tableB), and the data to populate tableA.field1 could be in either of 2 records in tableB. I want to try for the data (tableB.field2) from one record in tableB based on a criterion in another field in tableB (tableB.field3). If there is data in tableB.field2 for that record, that is great, I update tableA.field1 with that data, if tableB.field2 is empty, I want to requery tableB using a different value for my tableB.field3 criterion.
Example (I want to duplicate this logic and I am wondering if I can do it all inside of my cursor):
set tableA.field1 = (Select tableB.field2 from tableB where tableB.field3 ='abc')
If tableA.field1 is null Then
Set tableA.field1 = (Select tableB.field2 from tableB where tableB.field3 ='xyz')
I would like to be able to do this while I am sitting on an individual record in my update cursor, but I don't know if this is possible.
Any help would be appreciated.