COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: arroju_venkat on 17 Nov 2011 04:04:09 AM

Title: how to run report till current_date, when date is like 20111117
Post by: arroju_venkat on 17 Nov 2011 04:04:09 AM
Hi,

I have a date cloumn like 20111117 (=Nov 17, 2011), and the report should run till current_date.
Could you please let me know how to apply the filter.
Title: Re: how to run report till current_date, when date is like 20111117
Post by: HalfBloodPrince on 17 Nov 2011 04:32:21 AM
What is the data type of the date column character or it is numeric ?
Title: Re: how to run report till current_date, when date is like 20111117
Post by: arroju_venkat on 17 Nov 2011 04:37:30 AM
Date column datype is nVarChar
Title: Re: how to run report till current_date, when date is like 20111117
Post by: HalfBloodPrince on 17 Nov 2011 05:01:03 AM
try this query calculation as sysdate in that add
cast(extract(year,sysdate()),varchar(5))+
cast(extract(month,sysdate()),varchar(5))+
cast(extract(day,sysdate()),varchar(5))

then add filter
date=sysdate
Title: Re: how to run report till current_date, when date is like 20111117
Post by: blom0344 on 17 Nov 2011 01:35:20 PM
It is slightly more complex, as you need to compensate for months 1-9

date 2011-09-30 would become  '2011930' instead of  '20110930'

case
when month(current_date) < 10
then
(cast(extract(year,current_date),varchar(4))||
'0' ||
cast(extract(month,current_date),varchar(2))||
cast(extract(day,current_date),varchar(2))
)
else
(cast(extract(year,current_date),varchar(4))||
cast(extract(month,current_date),varchar(2))||
cast(extract(day,current_date),varchar(2))
)
end

I would also use  current_date as Cognos type and || for concatenation
Title: Re: how to run report till current_date, when date is like 20111117
Post by: pricter on 17 Nov 2011 01:54:34 PM
This can be down also without the case

cast(extract(year,current_date),varchar(4))||
right('0' ||cast(extract(month,current_date),varchar(2)),2)||
cast(extract(day,current_date),varchar(2))
Title: Re: how to run report till current_date, when date is like 20111117
Post by: blom0344 on 17 Nov 2011 01:56:49 PM
Ah, very good indeed!!    ;)
Title: Re: how to run report till current_date, when date is like 20111117
Post by: arroju_venkat on 18 Nov 2011 01:51:16 AM
Thanks a lot for your quick reply....

I am using it like this, is working fine (similar to HalfBooldPrince's reply).

cast(extract(year,current_date),varchar(5))+
cast(extract(month,current_date),varchar(5))+
cast(extract(day,current_date),varchar(5))
Title: Re: how to run report till current_date, when date is like 20111117
Post by: pricter on 18 Nov 2011 03:23:48 AM
It worked fine cause we have November and
extract(month,current_date) will return 11
on December will return 12 (so you will not have a problem)
but on January will return 1 and this will not work if your store month such as 01.

Now that I am thinking if you store days that r less than 10 like 01,02,03 etc you have to do this also for days.