I am working with a database schema that I cannot change – and I need to run a bulk update. I am moving data between source and target databases, with the same schema. I know this is awful, but it is what I am working with right now.
The schema is as follows:
Car
CarType1
CarType2
CarType3
CarType4
What I am trying to do – is bring over the CarTypes from my source database, by updating the target CarTypes.
My question is:
If my source record for car “BMW” has 3 CarTypes specified like so:
Car: BMW
CarType1: Fast
CarType2: Well Made
CarType3: Good Handling
CarType4: NULL
and my target has:
Car: BMW
CarType1: Fun Car
CarType2: NULL
CarType3: NULL
CarType4: NULL
How would I write an update statement such that CarType1-2-3 from the source would fill in the available NULL fields on the target? So Source:CarType1 -> Target:CarType2. And also – would there be a way to cancel out of the bulk update for this record and log a message if there wasn’t room in the target for all of the source fields(say if there’s 4 CarType values in my source, and only 3 NULL CarType columns in the corresponding target row?
Thank you!
I don’t know about doing it in one statement but four UPDATE statements do the trick.
The final select shows you what columns have overflowed.