473,379 Members | 1,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

update customer id numbers

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.
Aug 4 '11 #1
14 2040
Rabbit
12,516 Expert Mod 8TB
'M' + replicate('0', 9 - len(cast(id as varchar(10)))) + cast(id as varchar(10))
Aug 4 '11 #2
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?
Aug 4 '11 #3
Rabbit
12,516 Expert Mod 8TB
I'm not sure what the Enterprise Manager is. I normally use the SQL Server Management Studio. You would just use that in an update query.
Expand|Select|Wrap|Line Numbers
  1. UPDATE tableName SET id = ...
Aug 4 '11 #4
Ok, I think I understand if you will bear with me one more time. The acutal Table is PatientIdentifier and the column is ID_
so would the script run as:
UPDATE PatientIdentifier SET ID_ = 'M' + replicate('0', 9 - len(cast(id as varchar(10)))) + cast(id as varchar(10))
Aug 4 '11 #5
Rabbit
12,516 Expert Mod 8TB
You would need to change the id in the expression as well. I just used id cause I didn't know what your field was called.
Aug 4 '11 #6
The ID_ is the correct column name that contains the id numbers.
Aug 4 '11 #7
Rabbit
12,516 Expert Mod 8TB
Yes but id is not correct.
Aug 4 '11 #8
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?
Aug 4 '11 #9
Here is my script as it is written.
UPDATE PatientIdentifier SET ID_ = 'M' + replicate('0', 9 - len(cast(ID_ as varchar(10)))) + cast(ID_ as varchar(10))
Aug 4 '11 #10
Rabbit
12,516 Expert Mod 8TB
I don't know what you mean by only update the lines that need updating. You didn't mention that you only wanted to update certain records. This will update every record unless you specify a WHERE clause.
Aug 4 '11 #11
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.
Aug 4 '11 #12
Rabbit
12,516 Expert Mod 8TB
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.
Aug 4 '11 #13
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.
Aug 5 '11 #14
Rabbit
12,516 Expert Mod 8TB
Not a problem Joseph. If you want to learn about the where clause, I suggest the tutorials by wc3.
Aug 5 '11 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: ajay | last post by:
How to write a single update sql statement to update different set of attributes of a table. In other words what will be the value of indicator variables to ignore updates of some attributes in a...
3
by: Fred | last post by:
Hi out there, I have problems finding a way to warn a user that another user intends soon to update the same specific row. Let me explain. User 1 get to a JSP "update customer record" page....
4
by: dp | last post by:
After looking and looking, it appears that Access ADPs graphic query designer won't display: update customer set = . from customer, where customer. = .; It comes up with the "Query...
3
by: Matt Smolic | last post by:
Does anyone know where I can get some info on creating customer account numbers, part numbers and such. In other words what the logic is behind their creation. I am not looking for code, just how...
5
by: HydroSan | last post by:
Having a bit of a problem getting UPDATE working. The project in question is a simple MySQL VB.NET frontend, allowing Insertion, Selection, and others. Well, I've gotten Drop and Insert working,...
1
by: Dragon | last post by:
I am using mysql with the InnoDB engine. I wrote a perl script that first selects something from a table, and then updates a second table based on the select from the first table. I need to make...
12
by: shane.taylor81 | last post by:
Consider the following table Customer custId char(10) accountExpiryDate datetime accountStatus bit Now, I want to update the accountStatus to False as soon as the current date becomes...
2
by: kashigal | last post by:
<? session_start(); require("db.php"); mysql_connect(MACHINE, USER, ''); mysql_select_db(DBNAME); $username = $_SESSION; $pwd =$_SESSION;
0
by: AmitIper | last post by:
This Post is used to show how to bulk update records from grid view rather to updating one by one. The concept : create a xml string(string will contain all the records to be updated with some...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.