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] SQL to WebFOCUS

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] SQL to WebFOCUS
 Login/Join
 
Platinum Member
posted
Hello

Is there a way to convert SQL to WebFOCUS? I cannot use SQL passthrough. I am trying to convert below code. Any help is appreciated?
SELECT A.STATE,  
CASE WHEN SUM(CASE WHEN A.CITY = 'EDI' OR A.CITY = 'JC' THEN 1 ELSE 0 END) = 0 THEN 'N' ELSE 'Y' END AS T1
FROM TAB.TABLE_NAME A
WHERE EXISTS
(SELECT '1' FROM TAB.TABLE_NAME B
	WHERE A.STATE = B.STATE 
	AND CURRENT DATE BETWEEN B.FROM_DT AND COALESCE(B.TO_DT,'12/31/9999')
	AND COALESCE(DATE(B.TD),'12/31/9999') = 
   (
      SELECT MAX(COALESCE(DATE(Z.TR_DT),'12/31/9999')) 
	  FROM TAB.TABLE_NAME Z
      WHERE B.STATE = Z.STATE AND B.CITY = Z.CITY
    )
)
AND A.STATE = 'NJ'
GROUP BY A.STATE  

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


WF 8.2.01 APP STUDIO
PDF,HTML,EXL2K,Active
 
Posts: 139 | Registered: July 21, 2011Report This Post
Gold member
posted Hide Post
quote:
BI_Developer


Try using EXTERNAL SQL. You may have to tweak the syntax to what webfocus would like though.

Give it a try...

Thanks


WebFOCUS 8
Windows, All Outputs
 
Posts: 70 | Registered: May 26, 2017Report This Post
Virtuoso
posted Hide Post
I may be wrong, but since B.STATE must be equal to Z.STATE and B.STATE equal to A.STATE and A.STATE equal to 'NJ', then your code may be simplified as per below
SELECT A.STATE,
       CASE WHEN SUM(CASE WHEN A.CITY = 'EDI' OR A.CITY = 'JC' THEN 1 ELSE 0 END) = 0 THEN 'N' ELSE 'Y' END AS T1
FROM TAB.TABLE_NAME A
WHERE A.STATE = 'NJ'
GROUP BY A.STATE  


But I suspect that you are requesting from three different tables even if you pseudo all with TABLE_NAME (e.g Sales table that have sale period) and that you don't really need to filter on 'NJ'.

Not a perfect option; it's just pseudo-code (not even tested and can even be simplified), but something similar to this may work if other option don't.
This is just to give ideas on how to explose an SQL query in multiple FOCUS requests.
When I don't know how to perform something, I like to do it step by step and then look to simplify it.

DEFINE FILE TABLE_NAME_Z
DT_Z /YYMD MISSING ON = IF TR_DT EQ MISSING THEN '9999/12/31' ELSE TR_DT;
END
TABLE FILE TABLE_NAME_Z
SUM MAX.DT_Z as 'MAX_DT_Z'
BY STATE
BY CITY
ON TABLE HOLD AS TBL_Z FORMAT FOCUS INDEX STATE CITY
END
-RUN

DEFINE FILE TABLE_NAME_B
TO_DT_B /YYMD MISSING ON = IF TO_DT EQ MISSING THEN '9999/12/31' ELSE TO_DT;
DT_B    /YYMD MISSING ON = IF DT    EQ MISSING THEN '9999/12/31' ELSE DT;
END
TABLE FILE TABLE_NAME_B
BY STATE
BY CITY
BY DT_B
WHERE CURRENT_DATE GE FROM_DT;
WHERE CURRENT_DATE LE TO_DT_B;
ON TABLE HOLD AS TBL_B FORMAT FOCUS
END
-RUN

JOIN
     STATE AND CITY IN TBL_B TAG T1
  TO STATE AND CITY IN TBL_Z TAG T2 AS J1
END
TABLE FILE TBL_B
BY T1.STATE
WHERE DT_B EQ MAX_DT_Z;
ON TABLE HOLD AS TBL_C FORMAT ALPHA
END
-RUN

JOIN CLEAR *
END

DEFINE FILE TABLE_NAME_A
COND /I3 = IF CITY EQ 'EDI' OR 'JC' THEN 1 ELSE 0;
END
TABLE FILE TABLE_NAME_A
SUM COND NOPRINT
    COMPUTE T1 /A1 = IF COND EQ 0 THEN 'N' ELSE 'Y';
BY STATE
WHERE STATE IN FILE TBL_C;
-*WHERE STATE EQ 'NJ';
END
-RUN


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
 
Posts: 2409 | Location: Montreal Area, Qc, CA | Registered: September 25, 2013Report This Post
Platinum Member
posted Hide Post
Thank you Martin. A, B and Z is the same table. I will try your code.
quote:
Originally posted by MartinY:
I may be wrong, but since B.STATE must be equal to Z.STATE and B.STATE equal to A.STATE and A.STATE equal to 'NJ', then your code may be simplified as per below
SELECT A.STATE,
       CASE WHEN SUM(CASE WHEN A.CITY = 'EDI' OR A.CITY = 'JC' THEN 1 ELSE 0 END) = 0 THEN 'N' ELSE 'Y' END AS T1
FROM TAB.TABLE_NAME A
WHERE A.STATE = 'NJ'
GROUP BY A.STATE  

But I suspect that you are requesting from three different tables even if you pseudo all with TABLE_NAME (e.g Sales table that have sale period) and that you don't really need to filter on 'NJ'.


WF 8.2.01 APP STUDIO
PDF,HTML,EXL2K,Active
 
Posts: 139 | Registered: July 21, 2011Report This Post
Member
posted Hide Post
There are multiple ways to covert this to WF. You would first have to create synonyms of the tables in WF. Then in a procedure, you can create individual hold files that contain the pertinent rows from the tables specified and then join and report from them. Secondly, after creating individual table synonyms in WF, a cluster synonym of the tables can be created which can also include filter logic needed in your query.


WF 82 Windows
 
Posts: 5 | Location:  | Registered: October 25, 2019Report This Post
Guru
posted Hide Post
Can you use SQL pass through once? If so you could let the server generate the FOCUS code for you and then use it. Go to the server console and create a new procedure. Disable APT so that FOCUS is generated instead of SQL, and the put in your SELECT statement like this:

SQL SET APT=OFF END
SQL SELECT somecolumn FROM sometable WHERE somecondition ;
END 


Then click on the user icon and select Session Log. In the editor look for the
TABLE FILE sometable  
command. Copy paste the TABLE request to where you need it.


N/A
 
Posts: 397 | Location: New York City | Registered: May 03, 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] SQL to WebFOCUS

Copyright © 1996-2020 Information Builders