Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Concat Issue

Concat Issue

Concat Issue

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;

RE: Concat Issue

Without spending a lot of time on it, it looks like something is wrong with the CASE/ CAST statement where you are trying to get the integer value of SIZE_3. How big the size_3 char field? Does the CAST part of price return the correct values? What values are valid for the size_3 field? Have you tried simplifying the conversion of that size_3 calculation?
Simplifying the query does produce the desired result:


create table inventry_tt
wholesale_1 integer,
size_3 char);
insert into inventry_tt values (1, '1');
insert into inventry_tt values (5, '2');

select wholesale_1, size_3
,replicate('0',5) + cast(round((wholesale_1/cast(size_3 as integer))*100,0) as VARCHAR(10))
from inventry_tt; 


wholesale_1   size_3   EXPR_1
          1   1        00000100                                                                                                                                                                                                
          5   2        00000250 


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close