Skip to content

SQL to Append all Fields if Shorter than a set Length

This came in very handy for me at one point because I needed to have a certain field in each row 14 characters long, but half of them were only 12 characters long.

In MySQL:

update `table` set `field` = CONCAT(`field`, '1') where LEN(`field`) = 13;
Code language: SQL (Structured Query Language) (sql)

In MSSQL:

update `table` set `field` = CONCAT(`field`, '1') where LENGTH(`field`) = 13;
Code language: SQL (Structured Query Language) (sql)

See also  How to Binary to Text (ASCII) Conversion in Python
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x