COGNOiSe.com - The IBM Cognos Community

IBM Cognos Analytics Platform => Cognos Analytics => Reporting => Topic started by: peewan on 27 Feb 2020 09:15:41 AM

Title: First 5 digits Zipcode with 0 in front
Post by: peewan on 27 Feb 2020 09:15:41 AM
the [Zip] original data type: varchar (10), value 820010121, 085492561...

I would like to get first 5 digits of zip code only.

My data item:  trim(substring(cast([zip], varchar(10)), 1, 5))

Zip code with value:
820010121 return '82001' - WORKED
085492561 return '85492' - NOT WORKED - missing '0' at front. How would I fix this?

Thank you
Title: Re: First 5 digits Zipcode with 0 in front
Post by: adam_mc on 27 Feb 2020 09:26:26 AM
If its already a varchar(10) data item you should not need to trim - substring([Zip], 1, 5) should work.

Hope this helps.
Adam.
Title: Re: First 5 digits Zipcode with 0 in front
Post by: peewan on 27 Feb 2020 09:47:25 AM
Sorry for this, but i just check original data in Toad,  the zipcode with 0 in the front show up '23562639', so it is missing '0' from the raw data if it have 0 in front - and showed up as 8 digits only.

How could i fix it in cognos.
Thank you
Title: Re: First 5 digits Zipcode with 0 in front
Post by: peewan on 27 Feb 2020 10:11:55 AM
Hello,

i got this from another topic. Thanks a lot.

From <https://www.cognoise.com/index.php?topic=32504.0>