Skip to main content
Announcements
Qlik Acquires Upsolver to Advance Iceberg Solutions: READ MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Length of a number with leading zeros

Hi all,

I have a problem to calculate the length of a numeric field with leading zeros.

My field comes from a MySQL database and has values like these:

Number

000

1

39

001301

I need to calculate the length of Number in the script and I want to count the zeros too.

I want this result:

Number        Length_Number

000                   3

1                      1

39                     2

001301              6


I tried to use  in the script

load *,

len(Number) as Length_Number ;

sql select  Number

from table;


but it results:

Number        Length_Number

000                   1

000                   2

000                   3

000                   4

.......

000                   13

1                      1

39                     2

39                     4

001301              6

001301              8


and so on.


I tried to use

load *;

sql select  Number,

char_length(Number) as Length_Number;

from table;


and I had the same result.


Can someone help me? Thanks.

12 Replies
MarcoWedel

Just noticed that zeros should also count, so my answers are incorrect ...

wlpike
Contributor III
Contributor III

hi, 

did you ever find a solution for your leading zero issue?

 

thx

br

chris