473,397 Members | 1,949 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,397 software developers and data experts.

UPDATE Record's

Hi Dude's,

i want to update the cutomer table in customer id UA001 to UA0001, UA100 to UA0100 like that all records, i have plenty of records in this table please help me. I am using Sql Server 2005.


Thanks & Regards,
J Suresh
Aug 22 '08 #1
5 1232
ck9663
2,878 Expert 2GB
Find it here

Just use the WHERE clause.

-- CK
Aug 22 '08 #2
Delerna
1,134 Expert 1GB
If I understand your question correctly, then

Expand|Select|Wrap|Line Numbers
  1. UPDATE CustomerTable SET CustID=left(CustID,2) + '0' + right(CustID,len(CustID)-2)
  2.  
you might want to test that with a select before running the update first.
Expand|Select|Wrap|Line Numbers
  1. SELECT CustID,left(CustID,2) + '0' + right(CustID,len(CustID)-2) as NewCustID
  2. FROM CustomerTable
  3.  
if the NewCustID looks OK, then you can run the update.
Aug 22 '08 #3
Hi,

Thanks for your reply, When i use the SELECT query its working fine,

Party_id(char-15) Customer_id(varchar-15)
SA00001 SA000001 *******
SA00002 ******* SA000002 *******
SA00003 ******* SA000003 *******
SA00004 ******* SA000004 *******
SA00005 ******* SA000005 *******

While try to UPDATE its showing error becoz its a varchar(15) datatype.

I place the error below.

Error :
Msg 8152, Level 16, State 14, Line 1
String or binary data would be truncated.
The statement has been terminated.

Please help me in this

If I understand your question correctly, then

Expand|Select|Wrap|Line Numbers
  1. UPDATE CustomerTable SET CustID=left(CustID,2) + '0' + right(CustID,len(CustID)-2)
  2.  
you might want to test that with a select before running the update first.
Expand|Select|Wrap|Line Numbers
  1. SELECT CustID,left(CustID,2) + '0' + right(CustID,len(CustID)-2) as NewCustID
  2. FROM CustomerTable
  3.  
if the NewCustID looks OK, then you can run the update.
Aug 25 '08 #4
Delerna
1,134 Expert 1GB
Are you sure its a varchar(15) and not char(15)

If it's char(15) then try this
Expand|Select|Wrap|Line Numbers
  1. UPDATE CustomerTable SET CustID=left(rtrim(CustID),2) + '0' + right(CustID,len(rtrim(CustID))-2)
  2.  
char(15) will have 15 characters.....always. So the original update query would make it 16 characters and therefore generate the error.

If it is varchar(15) then one or more fields has 15 characters in them and adding the extra character makes 16 and therefore the error.
In this case you will need to chage the field in the table so it is varchar(16)
Aug 26 '08 #5
Thank you ,

Its working excelent.

Thanks & Regards,
JSuresh

Are you sure its a varchar(15) and not char(15)

If it's char(15) then try this
Expand|Select|Wrap|Line Numbers
  1. UPDATE CustomerTable SET CustID=left(rtrim(CustID),2) + '0' + right(CustID,len(rtrim(CustID))-2)
  2.  
char(15) will have 15 characters.....always. So the original update query would make it 16 characters and therefore generate the error.

If it is varchar(15) then one or more fields has 15 characters in them and adding the extra character makes 16 and therefore the error.
In this case you will need to chage the field in the table so it is varchar(16)
Aug 27 '08 #6

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

Similar topics

2
by: Reply via newsgroup | last post by:
Folks, When performing an update in mysql (using PHP), can I find out how many records were matched? mysql_affected_rows() won't work... and I have the following problem that I thought I...
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....
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
3
by: Mihaly | last post by:
I want to update a record into a table in SQL Server 2000 database from C#. This table is used concurently for other users too, and I want to be sure that from the read of record to the update no...
3
by: Shapper | last post by:
Hello, I have created 3 functions to insert, update and delete an Access database record. The Insert and the Delete code are working fine. The update is not. I checked and my database has all...
5
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I...
5
by: Louis LeBlanc | last post by:
Hey folks. I'm new to the list, and not quite what you'd call a DB Guru, so please be patient with me. I'm afraid the lead up here is a bit verbose . . . I am working on an application that...
2
by: Brett | last post by:
My database has 2 tables: Table1 & Table2. If a field is not null on a record in table2, then the not null fields in table1 that correspond to the records in table1 needs to be updated to match the...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.