Focal Point
[CLOSED] Is there a way in Webfocus/Infoassist to use CASE statements as sql does.

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/4287051096

May 15, 2018, 07:16 AM
Ghouse
[CLOSED] Is there a way in Webfocus/Infoassist to use CASE statements as sql does.
Is there a way in Webfocus/Infoassist to use CASE statements as sql does.

Example:

case WHEN TIMESTAMPDIFF(SQL_TSI_DAY, CAST("LOB Dimension".LOB_RCVD_001 AS DATE),CAST (CURRENT_DATE AS DATE) ) BETWEEN 6 AND 10 then "Work Fact".Count else 0 end

Here When i Say LOB_RCVD_001 it is Application Received date.

Wanted to know how to have this Query set in Infoassist to get the results with the count for the days given above

This message has been edited. Last edited by: FP Mod Chuck,


WebFOCUS 8

Windows, Active Report
May 15, 2018, 07:50 AM
BabakNYC
My SQL is rusty. Could you explain what you're trying to accomplish? From what I can tell, this is just an IF THEN ELSE in a DEFINE or a COMPUTE but maybe there's more to it than that.


WebFOCUS 8206, Unix, Windows
May 15, 2018, 08:01 AM
MartinY
Use something such as (in a DEFINE or COMPUTE):

DateDiff /I3 = HDIFF(CURRENT_DATE, LOB_RCVD_001, 'day-of-year', 'I3');
TestDiff /I5 = IF DateDiff GE 6 and DateDiff LE 10 THEN Count ELSE 0;

Look into manual/help for how to use HDIFF and its component format/usage.


WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
May 15, 2018, 09:10 AM
Doug
Yes!

A CASE command that is encountered in the sequential flow of a procedure is not executed.

You assign a unique name to each function using the CASE command.

Syntax: How to Use the CASE Command
The syntax for the CASE command is:

CASE functionname [TAKES p1/t1[,..., pn/tn]] [RETURNS result/t] [;]
[declarations]
commands
.
.
.
ENDCASE

Source: F1/Help from within App Studio.
May 15, 2018, 04:53 PM
Waz
quote:
CASE functionname [TAKES p1/t1[,..., pn/tn]] [RETURNS result/t] [;]


I think you will find that CASE is in Maintain.

You should be able to issue ANSI SQL with a case command against any data source.

SQL
select country
case
when country = 'ENGLAND' then 'UK'
when country in ('W GERMANY','ITALY','FRANCE') then 'EUROPE'
else 'Other' END
from car
;
END



Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

May 16, 2018, 08:55 AM
Doug
quote:
CASE is in Maintain

Really, Maintain Only??? OK, if so, I stand corrected.
May 16, 2018, 04:47 PM
Waz
quote:
Really, Maintain Only??? OK, if so, I stand corrected.


Well, in relation to 8.1.04, haven't checked 8.2 documentation


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

May 18, 2018, 10:57 AM
Doug
"CASE Statements": Sounds like it should be a NFR...
May 21, 2018, 08:46 AM
jgelona
quote:
Originally posted by Doug:
"CASE Statements": Sounds like it should be a NFR...


How is CASE different than DECODE? I have numerous requests where I have a WHERE on a DECODE value in a DEFINE and when I look at the SQL generated, the DECODE is converted to a SQL CASE statement.


In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
May 21, 2018, 04:52 PM
Waz
quote:
How is CASE different than DECODE?


SQL CASE supports returning the results of a formula.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

May 22, 2018, 04:28 AM
Martin vK
As mentioned by someone before, I think with IF THEN ELSE IF THEN ELSE IF .... you can do what CASE does in SQL. Actually if you look at the generated SQL you will find that IF THEN ELSE in a DEFINE or COMPUTE will be translated into a CASE statement.


WebFocus 8206M, iWay DataMigrator, Windows, DB2 Windows V10.5, MS SQL Server, Azure SQL, Hyperstage, ReportCaster