473,396 Members | 2,013 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,396 software developers and data experts.

update first 3 chars

ddtpmyra
333 100+
I have records like:

abc -books
acc -papers

now what I wanted to to is to update the first three (3) characters into:

xxx -books
xxx -papers

without doing anything after the dash (-) or leave the 'book' and 'paper'
I tried to do this way but I got error message:

MYSQL
update table1 set LEFT(name,3)='xxx-';
ERROR:
Expand|Select|Wrap|Line Numbers
  1. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT(name,3)='xxx-' where name in ('books','pens')'' at line 1
Jan 5 '10 #1

✓ answered by Atli

Hey.

Try something like:
Expand|Select|Wrap|Line Numbers
  1. UPDATE `stuff`
  2.     SET `field` = CONCAT('xxx', SUBSTRING(`field`, 4));

4 8442
Atli
5,058 Expert 4TB
Hey.

Try something like:
Expand|Select|Wrap|Line Numbers
  1. UPDATE `stuff`
  2.     SET `field` = CONCAT('xxx', SUBSTRING(`field`, 4));
Jan 6 '10 #2
nbiswas
149 100+
Try this

Query1:
Expand|Select|Wrap|Line Numbers
  1. update table1 set data = 'xxx' + SUBSTRING(data,4,LEN(data));
Query2:
Expand|Select|Wrap|Line Numbers
  1. update table1  set data = 'xxx' + RIGHT(data,LEN(data) - 3) 

Output:

Expand|Select|Wrap|Line Numbers
  1. data
  2. xxx -books
  3. xxx -papers
Jan 6 '10 #3
Atli
5,058 Expert 4TB
That's a bit dangerous though, nbiswas.
The REAPLCE function replaces all occurrences of the input string, so if the first three letters are repeated anywhere else in the string, those would get replaced as well.
Jan 6 '10 #4
ddtpmyra
333 100+
thanks for your help Atli!
Jan 6 '10 #5

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

Similar topics

1
by: Jochen Daum | last post by:
Hi ! I have this upate statement which gets sent to MS SQL: update MsgOutgoing set SenderResource = NULL,RecipientAddress = 'xxxxxxxxx',EarliestSentDateTime = NULL,LatestSentDateTime =...
4
by: joealey2003 | last post by:
Hi all... I have a column that contains names in upper case like: JOE, LAST NAME THOMAS JEFERSON MORS MIKE LEE ..
12
by: Axel | last post by:
Hiho, I want to read the content of a binary file into a string. It works, but only the first 4 chars are left after the reading and the stringsize is, of course, 4 bytes. I got this method...
20
by: hagai26 | last post by:
I am looking for the best and efficient way to replace the first word in a str, like this: "aa to become" -> "/aa/ to become" I know I can use spilt and than join them but I can also use regular...
2
by: Colleyville Alan | last post by:
I am trying to run an update query to take information in a field and remove the last 4 chars. For example, the following piece of data: DAA1.CTF, should be converted to DAA1 (without the ".CTF")....
6
by: Kifah Abbad | last post by:
Ok guys, here is the deal, i hope someone can help me out with this. I receive a string through a socket...i dunno how long this string is, but i save it all into a buf. .. .. ..
1
by: languy | last post by:
Hi there I'm having a problem when using the SqlDataAdapter. When calling the Update(DataSet, string) method I get the following error message "String or binary data would be truncated". The...
6
by: axapta | last post by:
Hi Group, How can I check that the first 2 characters of a string are the percent (%) sign? string name = strSurname Regards
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
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: 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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.