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
5 1232
Find it here
Just use the WHERE clause.
-- CK
If I understand your question correctly, then -
UPDATE CustomerTable SET CustID=left(CustID,2) + '0' + right(CustID,len(CustID)-2)
-
you might want to test that with a select before running the update first. -
SELECT CustID,left(CustID,2) + '0' + right(CustID,len(CustID)-2) as NewCustID
-
FROM CustomerTable
-
if the NewCustID looks OK, then you can run the update.
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 -
UPDATE CustomerTable SET CustID=left(CustID,2) + '0' + right(CustID,len(CustID)-2)
-
you might want to test that with a select before running the update first. -
SELECT CustID,left(CustID,2) + '0' + right(CustID,len(CustID)-2) as NewCustID
-
FROM CustomerTable
-
if the NewCustID looks OK, then you can run the update.
Are you sure its a varchar(15) and not char(15)
If it's char(15) then try this -
UPDATE CustomerTable SET CustID=left(rtrim(CustID),2) + '0' + right(CustID,len(rtrim(CustID))-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)
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 -
UPDATE CustomerTable SET CustID=left(rtrim(CustID),2) + '0' + right(CustID,len(rtrim(CustID))-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)
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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....
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
| |