COGNOiSe.com - The IBM Cognos Community

IBM Cognos 8 Platform => COGNOS 8 => Report Studio => Topic started by: Modtamod on 23 Jan 2008 12:58:02 PM

Title: URGENT PLease Help on Syntax of Multiple IF Statement
Post by: Modtamod on 23 Jan 2008 12:58:02 PM
On the GO Warehouse sample. I would like to I would like to create a mutiple if statement like

If ([First of Month Day of the week] = 5) THEN

([Sales].[Time].[Time].[Day].[Day of the month]-
3)
IF ([First of Month Day of the week] = 6)THEN

([Sales].[Time].[Time].[Day].[Day of the month]-
4)
IF ([First of Month Day of the week] = 7) THEN

([Sales].[Time].[Time].[Day].[Day of the month]-
5)

ELSE
([Sales].[Time].[Time].[Day].[Day of the month])


But I am getting a parsing error. Please help me with the correct syntax. I am new to Report Studio.
Title: Re: URGENT PLease Help on Syntax of Multiple IF Statement
Post by: Suraj on 23 Jan 2008 01:25:44 PM
Just add else in front of if except the first one:
If (xxx = xx) then ()
else if (uuu=uu) then ()
else if (......) then ()
else ....
Title: Re: URGENT PLease Help on Syntax of Multiple IF Statement
Post by: almeids on 23 Jan 2008 02:52:37 PM
I'm not sure if Suraj's suggestion will work (perhaps Cognos has made IF more flexible in Cognos8)...I've always found it necessary to enclose all 3 clauses in parentheses:

IF () THEN () ELSE ()

I used to have a lot of trouble with IF syntax, now I start them all by typing the above and then filling in the ()s.
Title: Re: URGENT PLease Help on Syntax of Multiple IF Statement
Post by: Suraj on 23 Jan 2008 03:31:43 PM
almeids,
yes, even after else, we need () depending on data type.
for example, usually else null with integer data types doesn't need () but for others, it is required.
I was pointing to the major flaw in the original if syntax and that was missing 'else' before secondary if's.
thanks
Title: Re: URGENT PLease Help on Syntax of Multiple IF Statement
Post by: jahnavi on 24 Jan 2008 02:38:38 AM
hi

chk out this is working

If ([First of Month Day of the week] = 5) THEN

([Sales].[Time].[Time].[Day].[Day of the month]-
3)
else IF ([First of Month Day of the week] = 6)THEN

([Sales].[Time].[Time].[Day].[Day of the month]-
4)
else IF ([First of Month Day of the week] = 7) THEN

([Sales].[Time].[Time].[Day].[Day of the month]-
5)

ELSE
([Sales].[Time].[Time].[Day].[Day of the month])

  and the syntax of if is if(condition) then(expression) else(expression) and if you try to use nested if then
                                              if(condition)
                                               then(expresion) else if(condition)
                                                 .........
                                                 else(expression)
                                                 
         hope this explanation will help you

Regards,
Jahnavi.