Rich Olu
asked on
Updating unique rows to become non-unique in SQL Server
I have a table with 3 columns containing values in rowid, documentNumver, customerNumber.
Col 2 contains mostly unique values although not always the case. The same is the case with col 3.
There are cases where for a particular documentNumber, there are a number of customerNumbers which are all unique.
In this cases, what I need to do is make the documentNumber unique for each customerNumber by changing the 3rd and 4th characters of the documentNumber to 01,02,03...
For eaxample,
rowid Document Customer
17738 2500000229 10106
17739 2500000229 10306
17740 2500000229 10146
So in the above case, I want the end result to be :
rowid Document Customer
17738 2501000229 10106
17739 2502000229 10306
17740 2503000229 10146
Your help will be highly appreciated.
R.
Col 2 contains mostly unique values although not always the case. The same is the case with col 3.
There are cases where for a particular documentNumber, there are a number of customerNumbers which are all unique.
In this cases, what I need to do is make the documentNumber unique for each customerNumber by changing the 3rd and 4th characters of the documentNumber to 01,02,03...
For eaxample,
rowid Document Customer
17738 2500000229 10106
17739 2500000229 10306
17740 2500000229 10146
So in the above case, I want the end result to be :
rowid Document Customer
17738 2501000229 10106
17739 2502000229 10306
17740 2503000229 10146
Your help will be highly appreciated.
R.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What is the datatype of DocumentNumber?
Also, what happens if you have a record like the following with only one Customer for a given DocumentNumber?
rowid Document Customer
17741 2500000230 10446
Should the DocumentNumber remain as is or should it be changed to 2501000230?
rowid Document Customer
17741 2500000230 10446
Should the DocumentNumber remain as is or should it be changed to 2501000230?
ASKER
awking00,
document number is currently varchar but I could change it if it makes life easier.
In response to your 2nd question, if there is only 1 cust / doc# then doc# remains the same.
There are also cases where there are more than 1 doc# and the cust is also the same. In this case also, the doc# is left as is.
For example:
rowid Document Customer
17741 2500000230 10446
17742 2500000230 10446
17743 2500000230 10446
Hope this makes sense.
Thanks.
document number is currently varchar but I could change it if it makes life easier.
In response to your 2nd question, if there is only 1 cust / doc# then doc# remains the same.
There are also cases where there are more than 1 doc# and the cust is also the same. In this case also, the doc# is left as is.
For example:
rowid Document Customer
17741 2500000230 10446
17742 2500000230 10446
17743 2500000230 10446
Hope this makes sense.
Thanks.
ASKER
awking00,
I am still awaiting your response if there is one, otherwise let me know so I can close this question.
Thanks.
I am still awaiting your response if there is one, otherwise let me know so I can close this question.
Thanks.
Sorry, I haven't abandoned you, but I've been extremely tied up and not had a chance to test a solution. If you come up with something that [always] works (although I'm not convinced the solutions proposed to date work in every case), please feel free to go ahead and close the question. If not, I will try to find time to work on this. :-)
ASKER
Although I haven't had the chance to test this and the project focus has somewhat changed but I trust the solution provided.
Thanks.
Thanks.