COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: srinu_anu2007 on 04 Sep 2012 03:22:11 AM

Title: Zip Code
Post by: srinu_anu2007 on 04 Sep 2012 03:22:11 AM
I have ZIP code column which is retriving as from data base but as per my requirement i wanna to display below like this.

iam having the 5 digit codes:
45612
45678,
12345,
789456123 like this

but i want to display, if eqal to 5 or more than 5 like below
78945-6123
iam using the below code but iam not getting
substring (ZIp),6,1) ='-'

can any one suggest?
Title: Re: Zip Code
Post by: MFGF on 04 Sep 2012 05:26:16 AM
Hi,

What data type is your Zip code item? I assume it's some sort of numeric field. If so, you should probably code your query calculation as follows:

if (character_length(cast([Your zip code item],varchar(15))) > 5) then (substring(cast([Your zip code item],varchar(15)),1,5) + '-' + substring(cast([Your zip code item],varchar(15)),6,5)) else (cast([Your zip code item],varchar(15)))

Cheers!

MF.
Title: Re: Zip Code
Post by: srinu_anu2007 on 04 Sep 2012 06:00:44 AM
Thanks! i got it using the below code.

case when length ([ZIP Column]) >5
then substr ([ZIP Column],1,5) || '-' ||
substr ([ZIP Column],6)
else [ZIP Column]
end