开发者

How to add a character

开发者 https://www.devze.com 2023-01-31 12:01 出处:网络
I have a table like this: ItemCode A123456 B123455 C23457 D开发者_JS百科123458 E23459 F The Code column must have 6 characters and I need to add \'1\' (for example, 23455 to 123455) for those items

I have a table like this:

Item          Code
A             123456
B             123455
C             23457
D           开发者_JS百科  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,


Update table
    set Code = CONCAT( '1', TRIM( Code ) )
  where LEN( TRIM( CODE ) ) < 6


For SQL Server and assuming the Code column is a character data type, you can do the following

UPDATE myTable
SET Code = '1' + Code
WHERE LEN(Code) < 6
0

精彩评论

暂无评论...
验证码 换一张
取 消