Focal Point
[CLOSED] converting select subquery in webfocus

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

March 08, 2012, 04:23 PM
Abu
[CLOSED] converting select subquery in webfocus
Hi,
I have a sql query that looks like this,
select a1.f1, a1.f2, a1.f3,
(select count(*) from a2 where a2.f1 = a1.f1 and a2.f2 = 'something') as "employee have no of a2 stuff"
from a1;
Any idea? why something is so easy in pl/sql but so complex in webfocus? How to use nested subquery in codition clause of main query in webfocus?
thanks
AK

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


WebFOCUS 7.6
Windows, All Outputs
March 09, 2012, 08:48 AM
Kevin Patterson
Hey Abu,
I believe you'll need to create a hold file to hold the results of your subquery on a2. Then join that hold file to a1.


Kevin Patterson
Appalachian State University
WebFOCUS 7.7.03
Windows, All Outputs
March 11, 2012, 11:00 AM
WF_IL
Hi

With WebFOCUS 77 You have the option to add a subquery on the master file level.
You can add a "virtual" field which will retrieve a single record from the sql sub-query,
then you can add a WHERE statement on this field which will be transalated to sql subquery request performed in the database.
You can download a presentation explaining how to use it given in Summit 2011:
metadata enhancements

Yours

Eran


Yours,
Eran
SRL Products

http://www.srl.co.il

March 12, 2012, 01:42 PM
Dan Satchell
Maybe something like this:

SET ALL = PASS
-*
JOIN f1 IN a1 TO ALL f1 in a2 as J1
-*
TABLE FILE a1
 SUM
  FST.a1.f2
  FST.a1.f3
  CNT.a2.f1 AS 'employee have no of a2 stuff'
 BY a1.f1
 WHERE (a2.f2 EQ 'something');
END



WebFOCUS 7.7.05
March 12, 2012, 02:18 PM
Kevin Patterson
You can also use the SQL Report Wizard. It allows you to insert sql directly into a Webfocus report. When you create a new procedure, in the window that pops up, change the "create with:" field to SQL Report Wizard.


Kevin Patterson
Appalachian State University
WebFOCUS 7.7.03
Windows, All Outputs
March 12, 2012, 03:15 PM
j.gross
@Dan -

Maybe not. We are not told whether (f1, f2, f3) covers the primary key of a1, so the answer set may well contain duplicate rows.

A PRINT verb and a "conditional" left outer join would be needed to cover that possibility; or a carefully crafted MATCH FILE.


- Jack Gross
WF through 8.1.05
March 19, 2012, 09:09 AM
Abu
Thanks everyone for sharing your knowledge. Actually, the task for me was to determine if an employee is an alumni or not in our university. I had to count no of degrees awarded by our university for an employee and if someone has 1 or more degrees then he/she is an alumni. It was very simple in Oracle, i.e pl/sql.
However, for webfocus, I had to select all records from degree table and save it in a hold file (a very tiny fraction from university degree table are also an employee in our university). Then I joined this degree table with the original report containing all the current university employees. Then count degrees for all employees and if the count is > 0 then he/she is an alumni else not an anlumni. The report is working fine. However, I don't like the idea of selecting all records from the degree table and save it in a hold file. In pl/sql it could have been just a single subquery selecting from the degree table using emplyee ID. Because the degree table is huge it contains all the degrees awarded by the university from its inception but our university has only couple of thousand employees. Anyway, the report is working, thats the bottomline.
Thanks
Abu


WebFOCUS 7.6
Windows, All Outputs
March 19, 2012, 09:43 AM
RSquared
Could you not join the Employee table to the Degree table and then count the number of times an employee is on the degree table ?


WF 7.6.11
Oracle
WebSphere
Windows NT-5.2 x86 32bit