Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove first character from mysql field

Tags:

mysql

I need advices in order to make a process on my list of values. I have a table llx_societe and some fields where one of them is code_client. This field looks like :

0099
00100
00101
00102
...
00998
00999
001000

I want to remove the first zero for all values between 00100 and 00999 in order to get 0100 until 0999.

I wrote this command :

UPDATE `llx_societe` 
SET `code_client`= SUBSTR(code_client,1) 
WHERE `code_client` BETWEEN '00100' AND '00999';

But nothing, none lines are proceed.

Have you an explanation ?

like image 299
Essex Avatar asked Nov 01 '16 13:11

Essex


People also ask

How do I remove the first character in SQL?

To delete the first characters from the field we will use the following query: Syntax: SELECT SUBSTRING(string, 2, length(string));

How do I change the first character in MySQL?

Use the MySQL REPLACE() function to replace a substring (i.e. words, a character, etc.) with another substring and return the changed string.

What is trim MySQL?

MySQL TRIM() Function The TRIM() function removes leading and trailing spaces from a string.


1 Answers

SQL starts counting from 1 and not 0. Try this:

UPDATE `llx_societe` 
SET `code_client`= SUBSTR(code_client,2) 
WHERE `code_client` BETWEEN '00100' AND '00999';
like image 171
mshaugh Avatar answered Nov 15 '22 16:11

mshaugh