COGNOiSe.com - The IBM Cognos Community

IBM Cognos 10 Platform => Cognos 10 BI => Framework Manager => Topic started by: cognosun on 04 Feb 2013 06:18:22 AM

Title: Conditon syntax in SQL
Post by: cognosun on 04 Feb 2013 06:18:22 AM
Hi,

We use Oracle SQL.

I got a column ( a) with "timestamp" data type and another column (b) with 'number' data type.

How shall i write a condition...

if year value in 'a' = 2013 then year value in 'b' is 2012 ( a-1)
if year value in 'a' = 2012 then year value in 'b' is 2011 ( a-1)

Many thanks in advance.
Title: Re: Conditon syntax in SQL
Post by: CognosPaul on 04 Feb 2013 06:27:11 AM
You need to filter all rows where b is equal to year(a)-1? You say that b is numeric, do you mean something like 20120101 or 2012?

Try doing something like
substr(to_char([b]),1,4) = to_char(add_months([a],-12),'yyyy')

EDIT: I forgot that [b] is actually a forum tag for bold.