COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: learnflower on 16 Dec 2011 01:52:57 AM

Title: IF else function and DATE format
Post by: learnflower on 16 Dec 2011 01:52:57 AM
HI ,

I am using this 
cast(cast((extract(month,current_date)), varchar(2)), integer)-1||'/'||cast(substring((cast((extract(year,current_date)), varchar(4)) ),3), integer)-1
in a if and else i am getting the 'sqlPrepareWithOptions' status='-126'
but without having it in the if condition if i=run the tabular data i am getting required output .

But within the below if condition i am getting the below mentioned error

IF (cast((extract(month,current_date)), varchar(2))>'01')
THEN
  (cast((extract(month,current_date)), varchar(2))||'/'||substring((cast((extract(year,current_date)), varchar(4)) ),3))
ELSE
   (cast(cast((extract(month,current_date)), varchar(2)), integer)-1||'/'||cast(substring((cast((extract(year,current_date)), varchar(4)) ),3), integer)-1)

Please guide on this
Title: Re: IF else function and DATE format
Post by: blom0344 on 16 Dec 2011 06:10:14 AM
Looks to me you are trying to concatenate (   ||  )  strings and numerical values

Also why define:

(cast((extract(month,current_date)), varchar(2))>'01')

instead of:

extract(month,current_date) > 1

You need to clean your code..
Title: Re: IF else function and DATE format
Post by: learnflower on 19 Dec 2011 01:35:18 AM
Thanks Bloom0344 :)
Title: Re: IF else function and DATE format
Post by: blom0344 on 19 Dec 2011 01:44:35 AM
You're welcome! Now if you could just write my name properly   ;)
Title: Re: IF else function and DATE format
Post by: learnflower on 19 Dec 2011 05:56:38 AM
Sorry  :) for not writing ur name properly blom0344
Title: Re: IF else function and DATE format
Post by: MFGF on 19 Dec 2011 08:23:01 AM
Quote from: blom0344 on 19 Dec 2011 01:44:35 AM
You're welcome! Now if you could just write my name properly   ;)

Hee hee. Makes me smile every time! :)

Thanks Blom - you are a star!
Title: Re: IF else function and DATE format
Post by: blom0344 on 19 Dec 2011 02:14:17 PM
I fear this is becoming a running gag   :-\