Concatenate and dropping leading zeros

35 views Asked by At

Column A was formatted using Custom to include leading zeros. Colum B was concat to include format for use in SQL. There are over 11,000 lines in Column A.

image capturing data and concat

Need to figure out how to keep leading zeros in column B and still have format for sql

1

There are 1 answers

0
Mayukh Bhattacharya On

You could try one of the followings:

enter image description here


• Formula used in cell B1

=BASE(A1:A4,10,MAX(LEN(A1:A4)))

Or could use TEXT() + REPT() function combo:

=LET(a,A1:A4,TEXT(a,REPT("0",MAX(LEN(a)))))

Note that the use of MAX() & LEN() only because if the values in Column A has varying length of characters.


If the length of characters are not varying and remains same for the whole range could simplify it as :

enter image description here


=RIGHT(REPT(0,11)&A1:A4,11)

=BASE(A1:A4,10,11)

=LET(a,A1:A4,TEXT(a,REPT("0",LEN(a))))

Or as mentioned in comments by Scott Craner Sir if you want to combine all into one then using ARRAYTOTEXT() + TOCOL()

enter image description here


=ARRAYTOTEXT("'"&TOCOL(A:A,1)&"'")

If one don't have access to ARRAYTOTEXT() then:

=LET(_a,FILTER(A:A,A:A<>""),TEXTJOIN(", ",,TEXT(_a,REPT("0",LEN(_a)))))