Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Convert SQL CASE Statement to If Then Else

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] Convert SQL CASE Statement to If Then Else
 Login/Join
 
Guru
posted
Argh! I've been trying for the last few hours to convert the following SQL CASE statement into a form of If Then Else logic that WebFOCUS will accept!
Any ideas? Is there a rule-of-thumb to follow?

Here is the SQL code:
CASE WHEN (ENG_SOP < 1960) THEN
	CASE WHEN ((POP_YR - ENG_LIF_YRS) > 1960) THEN	
		CASE WHEN ((1996 - (POP_YR - ENG_LIF_YRS)) < 1.0)  THEN (1.0) 
		     WHEN ((1996 - (POP_YR - ENG_LIF_YRS)) >= 1.0) THEN (1996 - (POP_YR - ENG_LIF_YRS)) END
	     WHEN ((POP_YR - ENG_LIF_YRS) <= 1960) THEN (1996 - 1960) END
     WHEN (ENG_SOP >= 1960) THEN
	CASE WHEN ((POP_YR - ENG_LIF_YRS) > ENG_SOP) THEN 
		CASE WHEN ((1996 - (POP_YR - ENG_LIF_YRS)) < 1.0) THEN (1.0) 
		     WHEN ((1996 - (POP_YR - ENG_LIF_YRS)) >= 1.0) THEN (1996 - (POP_YR - ENG_LIF_YRS)) END
	     WHEN ((POP_YR - ENG_LIF_YRS) <= ENG_SOP) THEN
		CASE WHEN ((1996 - ENG_SOP) < 1.0) THEN (1.0) 
		     WHEN ((1996 - ENG_SOP) >= 1.0) THEN (1996 - ENG_SOP) END 
     ELSE 1.0 END END AS 'DAN'  


Thanks! Sweating

Dan

This message has been edited. Last edited by: Dan Pinault,


7.7.05M/7.7.03 HF6 on Windows Server 2003 SP2 output to whatever is required.
 
Posts: 393 | Location: St. Paul, MN | Registered: November 06, 2007Report This Post
Virtuoso
posted Hide Post
This is what I came up with.

VAL/D12.1 = IF (((POP_YR - ENG_LIF_YRS) GT 1960) OR ((POP_YR - ENG_LIF_YRS) GT ENG_SOP)) AND
                ((1996 - (POP_YR - ENG_LIF_YRS)) LT 1.0) THEN (1.0)                           ELSE
            IF (((POP_YR - ENG_LIF_YRS) GT 1960) OR ((POP_YR - ENG_LIF_YRS) GT ENG_SOP)) AND
                ((1996 - (POP_YR - ENG_LIF_YRS)) GE 1.0) THEN (1996 - (POP_YR - ENG_LIF_YRS)) ELSE
            IF ((ENG_SOP LT 1960) AND ((POP_YR - ENG_LIF_YRS) LE 1960)) THEN (1996 - 1960)    ELSE
            IF ((ENG_SOP GE 1960) AND ((POP_YR - ENG_LIF_YRS) LE ENG_SOP) AND
                ((1996 - ENG_SOP) LT 1.0)) THEN (1.0)                                         ELSE
            IF ((ENG_SOP GE 1960) AND ((POP_YR - ENG_LIF_YRS) LE ENG_SOP) AND
                ((1996 - ENG_SOP) GE 1.0)) THEN (1996 - ENG_SOP)                              ELSE (1.0);


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Report This Post
Virtuoso
posted Hide Post
How about this one? WebFOCUS syntax really helps to simplify those highly verbose CASE statements:

VAL/D12.1 = IF ENG_SOP LT 1960 
            THEN (IF (POP_YR - ENG_LIF_YRS) GT 1960    THEN MAX(1.0, 1996 - (POP_YR - ENG_LIF_YRS)) ELSE (1996 - 1960))
            ELSE (IF (POP_YR - ENG_LIF_YRS) GT ENG_SOP THEN MAX(1.0, 1996 - (POP_YR - ENG_LIF_YRS)) ELSE MAX(1.0, 1996 - ENG_SOP));


I didn't see a valid case where the final "ELSE 1.0" in the original code would apply as either (POP_YR - ENG_LIF_YRS) > ENG_SOP or (POP_YR - ENG_LIF_YRS) <= ENG_SOP would be met in any case, so I did not make a provision for that one.

Hope that helps,

- Neftali.

This message has been edited. Last edited by: njsden,



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
 
Posts: 1533 | Registered: August 12, 2005Report This Post
Virtuoso
posted Hide Post
Here's a snippet of code using the CAR table testing the different 7 possible cases you'd encounter based in the original CASE statement:

DEFINE FILE CAR
RC/I2 WITH CAR = RC + 1;
ENG_SOP/I6     = DECODE RC (1 1955 2 1955 3 1955 4 1970 5 1970 6 1970 7 1999 ELSE 0); 
POP_YR/I6      = DECODE RC (1 2005 2 1990 3 1978 4 2010 5 1990 6 1975 7 1975 ELSE 0); 
ENG_LIF_YRS/I6 = DECODE RC (1 8    2 25   3 30   4 5    5 10   6 10   7 10   ELSE 0);
-*
VAL/D12.1      = IF ENG_SOP LT 1960 
                 THEN (IF (POP_YR - ENG_LIF_YRS) GT 1960    THEN MAX(1.0, 1996 - (POP_YR - ENG_LIF_YRS)) ELSE (1996 - 1960))
                 ELSE (IF (POP_YR - ENG_LIF_YRS) GT ENG_SOP THEN MAX(1.0, 1996 - (POP_YR - ENG_LIF_YRS)) ELSE MAX(1.0, 1996 - ENG_SOP));
END
-*
TABLE FILE CAR
PRINT 
      RC          AS 'Case'
      ENG_SOP
      POP_YR
      ENG_LIF_YRS
      VAL         AS 'Result'
WHERE RC LE 7
END


Regards,
- Neftali.



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
 
Posts: 1533 | Registered: August 12, 2005Report This Post
Guru
posted Hide Post
Thanks for the help Dan and Neftali!

I guess I couldn't see the forest for the trees as the saying goes. I was stuck on trying to convert the statement as it was written. The though or rearranging it never occured to me. Doh! Red Face

Regards!

Dan


7.7.05M/7.7.03 HF6 on Windows Server 2003 SP2 output to whatever is required.
 
Posts: 393 | Location: St. Paul, MN | Registered: November 06, 2007Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Convert SQL CASE Statement to If Then Else

Copyright © 1996-2020 Information Builders