COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: rr.bi1212 on 19 Feb 2012 06:13:11 PM

Title: How to concatenate two fields with different datatypes in report studio??????
Post by: rr.bi1212 on 19 Feb 2012 06:13:11 PM
Hi,
My Question is how to concatenate two fields with different datatypes (i.e integer and varchar) in report studio??????

The Result should display in this way........field1 - field2.
Title: Re: How to concatenate two fields with different datatypes in report studio??????
Post by: HalfBloodPrince on 19 Feb 2012 10:27:26 PM
Use Cast([column name],VARCHAR(<length>) ) to convert integer column to Character. then you can concatenate.

For Eg. cast([Amount],varchar(10))

Title: Re: How to concatenate two fields with different datatypes in report studio??????
Post by: rr.bi1212 on 20 Feb 2012 12:03:15 AM
Half Blood Prince

I am concatenating at the field level so can you please tell me how to convert and concatenate it.
Title: Re: How to concatenate two fields with different datatypes in report studio??????
Post by: HalfBloodPrince on 20 Feb 2012 12:16:18 AM
cast([Field1],varchar(10) ) +'-' +[Field2]

assumed Field 2 is character
Title: Re: How to concatenate two fields with different datatypes in report studio??????
Post by: rr.bi1212 on 20 Feb 2012 09:13:12 PM
Thanx HalfBloodPrince.......Its working.
Title: Re: How to concatenate two fields with different datatypes in report studio??????
Post by: Lynn on 21 Feb 2012 07:29:33 AM
Another option is to unlock your report layout and drag the items in separately. If the requirement is simply to display field1 - field2 in the layout then you don't have to cast and concatenate in the query. Just drag them in as desired and use a text item for the hyphen between them.