I have this stupid table in our program db. Program is not ours so there is no way to change table contents. The table stores SQL like expressions in unreadable codes. I am translating those values back to SQL expressions to run these expressions. So far, the translating part goes very well. Result so far is a table like the following:
+--------+--------+---------+----------------+-----------------+
| CODE | SEQNUM | LOGICAL | EXPRESSION | EXPRESSIONVALUE |
+--------+--------+---------+----------------+-----------------+
| A23000 | 1 | NULL | OTHERCODE LIKE | 'A522%' |
+--------+--------+---------+----------------+-----------------+
| A23000 | 2 | OR | OTHERCODE = | 'A62342' |
+--------+--------+---------+----------------+-----------------+
| A23000 | 3 | OR | OTHERCODE = | 'A62343' |
+--------+--------+---------+----------------+-----------------+
| B43000 | 1 | NULL | OTHERCODE IN | 'B34324' |
+--------+--------+---------+----------------+-----------------+
| B43000 | 2 | NULL | NULL | 'B92338' |
+--------+--------+---------+----------------+-----------------+
| B43000 | 3 | NULL | NULL | 'B92342' |
+--------+--------+---------+----------------+-----------------+
| B43000 | 4 | NULL | NULL | 'B02349' |
+--------+--------+---------+----------------+-----------------+
| B43000 | 5 | OR | OTHERCODE = | 'B32443' |
+--------+--------+---------+----------------+-----------------+
Or order for me to have valid SQL statements, I need to have commas behind the rows where there is an 'in-expression'. I my opinion this needs to be based on earlier rows. I need to have a table like:
+--------+--------+---------+----------------+-----------------+------------+
| CODE | SEQNUM | LOGICAL | EXPRESSION | EXPRESSIONVALUE | CALCULETED |
+--------+--------+---------+----------------+-----------------+------------+
| A23000 | 1 | NULL | OTHERCODE LIKE | 'A522%' | NULL |
+--------+--------+---------+----------------+-----------------+------------+
| A23000 | 2 | OR | OTHERCODE = | 'A62342' | NULL |
+--------+--------+---------+----------------+-----------------+------------+
| A23000 | 3 | OR | OTHERCODE = | 'A62343' | NULL |
+--------+--------+---------+----------------+-----------------+------------+
| B43000 | 1 | NULL | OTHERCODE IN | 'B34324' | ',' |
+--------+--------+---------+----------------+-----------------+------------+
| B43000 | 2 | NULL | NULL | 'B92338' | ',' |
+--------+--------+---------+----------------+-----------------+------------+
| B43000 | 3 | NULL | NULL | 'B92342' | ',' |
+--------+--------+---------+----------------+-----------------+------------+
| B43000 | 4 | NULL | NULL | 'B02349' | NULL |
+--------+--------+---------+----------------+-----------------+------------+
| B43000 | 5 | OR | OTHERCODE = | 'B32443' | NULL |
+--------+--------+---------+----------------+-----------------+------------+
Is this possible to do with SQL?