ex. c1, c2 = > result
c1 c1 result
1 1 to 1000001
2 9 to 2000009
3 1 to 3000001
21 34 to 2100034
22 35 to 2200035
23 55 to 2300055
111 1234 to 1111234
112 8392 to 1128392
113 2833 to 1132833
a part of my MySQL SELECT CONCAT() statement with cut out "c1" look like,
IF(CHAR_LENGTH(`c2`)=1, concat('00000',`c2`),
IF(CHAR_LENGTH(`c2`)=2, concat('0000',`c2`),
IF(CHAR_LENGTH(`c2`)=3, concat('000',`c2`),
IF(CHAR_LENGTH(`c2`)=4, concat('00',`c2`),
IF(CHAR_LENGTH(`c2`)=5, concat('0',`c2`),`c2` )))))
But is there any other way to reduce this code for concat c1 with c1 into result with zero at the middle and with auto calculation of how many zeros have to be added?
There might be a math function to help you here, although I don’ t know if it is quicker.
Lets see. you want to multiply a single value for c1 by 1000000 and then add c2.
For the more general case, you want to multiply by
more:
Your final value will be
But that LPAD function from @eumiro might be a better answer