I have a table that contains customer Id numbers that are 5-8 characters. They need to be updated to 10 characters with a leading M and padded with zeros. I am new to this and would appreciate assistance.
update customer id numbers
Collapse
X
-
Tags: None
-
Thanks bunch Rabbit that looks like it is perfect. How can I make that run on the customerID field only in my database. Can I simply put the script into the edit steps field in Enterprise Manager?Comment
-
Ok, I think I understand if you will bear with me one more time. The acutal Table is PatientIdentifi er and the column is ID_
so would the script run as:
UPDATE PatientIdentifi er SET ID_ = 'M' + replicate('0', 9 - len(cast(id as varchar(10)))) + cast(id as varchar(10))Comment
-
-
Rabbit, I have created the script and all looks correct. I am almost ready to test. Will this script if run again only update the lines that need updating?Comment
-
Here is my script as it is written.
UPDATE PatientIdentifi er SET ID_ = 'M' + replicate('0', 9 - len(cast(ID_ as varchar(10)))) + cast(ID_ as varchar(10))Comment
-
I want to update them all now and the update the new ones that come in between now and the time we go live with the new system.Comment
-
That will update them all now. You can add a WHERE clause to filter out the ones that are already ten characters in length. But it should be handled on the client side. Otherwise, you will have to run the query periodically and the data won't be real time. Or you could handle it server side by setting up a stored procedure, which would require work on both the client side and server side but would be the most accurate.Comment
-
Thank you so much you have been extremely helpful. Since I do not know much about the WHERE statement I think I may just run the script 1 hour before we switch and then manually update the few that come in during the switch. Thanks again.Comment
Comment