开发者

How to add a character

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜