Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a character

Tags:

sql

I have a table like this:

Item          Code
A             123456
B             123455
C             23457
D             123458
E             23459
F           

The Code column must have 6 characters and I need to add '1' (for example, 23455 to 123455) for those items with less than 6 characters.

How can I do it with SQL ?

Thanks,

like image 288
Bob Avatar asked Jan 21 '23 21:01

Bob


1 Answers

Update table
    set Code = CONCAT( '1', TRIM( Code ) )
  where LEN( TRIM( CODE ) ) < 6
like image 192
Paul Morgan Avatar answered Jan 23 '23 10:01

Paul Morgan