I'm having a severe brain-freeze here, guys. Here's my dilemma: I have over 350 rows in my ADDRESS table in which a dataload has gone wrong.
Over 350 rows were inserted into the ADDLINE table with no respect for the LINENBR value. And as we all know, if the line numbers aren't set to 1 and 2 (respectively), the addresses will not print (or display) properly. So it's my job to update these rows accordingly.
Here's the catch. Each account could have only one row where the LINENBR could any number from 2 thru 5. Plus (as expected) there are accounts with more than one row with line numbers in sequential order (eg: 2,3 or 3,4 or 4,5). Now as much as I would like to do a "UPDATE ADDRLINE SET LINENBR = 1 where LINENBR = 2, SET LINENBR = 2 WHERE LINENBR = 3", this will not help me where I have single rows where LINENBR = 3.
Is there some type of magic I can work in SQL to get this to run properly, or will I have to manually separate the data set and run separate update queries for each set?
I'm thinking the best way to get this done to create a SQL script in which for each account get the lines in the order they're currently in. Then loop through each line and reset the line number. But I have no idea how to do this for both my single and double line instances.
Please help!!!
Thanks, Darrel
Over 350 rows were inserted into the ADDLINE table with no respect for the LINENBR value. And as we all know, if the line numbers aren't set to 1 and 2 (respectively), the addresses will not print (or display) properly. So it's my job to update these rows accordingly.
Here's the catch. Each account could have only one row where the LINENBR could any number from 2 thru 5. Plus (as expected) there are accounts with more than one row with line numbers in sequential order (eg: 2,3 or 3,4 or 4,5). Now as much as I would like to do a "UPDATE ADDRLINE SET LINENBR = 1 where LINENBR = 2, SET LINENBR = 2 WHERE LINENBR = 3", this will not help me where I have single rows where LINENBR = 3.
Is there some type of magic I can work in SQL to get this to run properly, or will I have to manually separate the data set and run separate update queries for each set?
I'm thinking the best way to get this done to create a SQL script in which for each account get the lines in the order they're currently in. Then loop through each line and reset the line number. But I have no idea how to do this for both my single and double line instances.
Please help!!!
Thanks, Darrel