I am trying to pad a calculated field with leading zeros, so if its original value is '1' then the new value would be '001'. Or if its original value was '23' the new value is '023'. Or if its original value is '124' then new value is the same as original value. I am using below code but it only shows zeros in the output not the field values and if I pad these zeros in the last it returns correct output.
Can someone help me? I am new with pervasive sql and using PSQL v12. Thanks in advance
My query: (wholesale_1 is double datatype & size_3 is char datatype)(field calculation is wholesale_1/size_3)
select wholesale_1, size_3
,replicate('0',5) + cast(round((wholesale_1/(case when left((case when size_3 = ' ' then cast('1' as int) when locate('*', size_3) > 0 then cast(left(size_3, locate('*', size_3)-1) as int) else
cast(size_3 as int) end),1) = 0 then 1
else (case when size_3 = ' ' then cast('1' as int)
when locate('*', size_3) > 0 then cast(left(size_3, locate('*', size_3)-1) as int)
else cast(size_3 as int) end) end))*100,0) as VARCHAR(10)) as price
from inventry;
Can someone help me? I am new with pervasive sql and using PSQL v12. Thanks in advance
My query: (wholesale_1 is double datatype & size_3 is char datatype)(field calculation is wholesale_1/size_3)
select wholesale_1, size_3
,replicate('0',5) + cast(round((wholesale_1/(case when left((case when size_3 = ' ' then cast('1' as int) when locate('*', size_3) > 0 then cast(left(size_3, locate('*', size_3)-1) as int) else
cast(size_3 as int) end),1) = 0 then 1
else (case when size_3 = ' ' then cast('1' as int)
when locate('*', size_3) > 0 then cast(left(size_3, locate('*', size_3)-1) as int)
else cast(size_3 as int) end) end))*100,0) as VARCHAR(10)) as price
from inventry;