How to use if then else

I have a table with two columns
col1 col2
A 1
AB 7
C 23
BD 27

Now i like to create and "if then else "
if the value in col2 <10 then “0” & value in col2
else value of col2
result should be

col1 col2 col3
A 1 01
AB 7 07
C 23 23
BD 27 27

You can do this with the Rule Engine node:

Similar question:



Hi Philipp,

Have this in the Rule engine node and result in col3
$col2$<10=>“0” & $col2$

but get an error
if i only put in first formula $col2$>9=>$col2$ there is no error but result is NOT OKE. Result is ?

Hi @RonG

An alternative is the string manipulation node (first convert your int to string).
When using length then number leading “0” will be adjust to the max length of your number.


1 Like

Hi there,

nice one with the String Manipulation node @HansS! Although length() function didn’t work :confused: Instead I did put number two and it worked.

Additionally @RonG you can use Column Expressions node. Only using Rule Engine won’t work here as it will not add “0” to single digit.


1 Like

@ipazin . It worked on my machine :smile:
@RonG Its also possible to make it in 2 Nodes, first length() and then the padLeft, using the outcome of length()
gr. Hans

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.