Consider following table
--------------------------------
ID | ColA | ColB | ColC
--------------------------------
1 | ABC | |
2 | | XYZ |
3 | PQR | |
4 | MNO | PQR |
Now I have to add a value (EFG) in this table where ID = 1 in any column like ColA, ColB or ColC depending on which is free (empty). This is done dynamically or programmatically (consider any language, I just want to know the logic).
For example:
If ID = 1, column ColB will be updated with value because it’s the first free column.
If ID = 2, column ColA will be updated with value because it’s the first free column.
If ID = 3, column ColB will be updated with value because it’s the first free column.
If ID = 4, column ColC will be updated with value because it’s the first free column.
since the record is already inserted, you only need to update the row,