Focal Point
select distinct

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

May 22, 2006, 07:55 AM
Anubha Saini
select distinct
Can anyone suggest how to write code in webfocus for select distinct query like this

select distinct
super.SUPVR_COST_ID,
RTRIM(SUPVR_LNAME) CONCAT ', ' CONCAT RTRIM(SUPVR_FNAME) CONCAT ' ' CONCAT RTRIM(SUPVR_MNAME) as FULL_NAME,
super.SUPVR_CODE,
vg2.LINE_SEG_NBR,
vg2.TRACK_SDTK_NBR,
integer(vg2.MILE_POST_BEG)/1000 + (vg2.MILE_POST_BEG - integer(vg2.MILE_POST_BEG)) as BEGMP,
integer(vg2.MILE_POST_END)/1000 + (vg2.MILE_POST_END - integer(vg2.MILE_POST_END)) as ENDMP,
vg2.SRVY_STN_LEN,
vg2.ELEV_BEG,
vg2.ELEV_END,
vg2.GRADE_PERCENT
from
RIS.TRPT_SUPERVISOR super,
RIS.VGRADE2 vg2
where
super.LINE_SEG_NBR = vg2.LINE_SEG_NBR
and super.SUPVR_COST_ID = ':5'
and super.SUPVR_COST_ID = ':6'
and abs(vG2.GRADE_PERCENT) >= :7
and 1=1
order by LINE_SEG_NBR, BEGMP, TRACK_SDTK_NBR
May 22, 2006, 08:01 AM
Tony A
Yes,

Retain your power within the SQL and pull a recordset using it -

ENGINE SQLORA SET SERVER adaptername
SET SQLENGINE = SQLORA
SQL
select distinct 
super.SUPVR_COST_ID, 
RTRIM(SUPVR_LNAME) CONCAT ', ' CONCAT RTRIM(SUPVR_FNAME) CONCAT ' ' CONCAT RTRIM(SUPVR_MNAME) as FULL_NAME, 
super.SUPVR_CODE, 
vg2.LINE_SEG_NBR, 
vg2.TRACK_SDTK_NBR, 
integer(vg2.MILE_POST_BEG)/1000 + (vg2.MILE_POST_BEG - integer(vg2.MILE_POST_BEG)) as BEGMP, 
integer(vg2.MILE_POST_END)/1000 + (vg2.MILE_POST_END - integer(vg2.MILE_POST_END)) as ENDMP, 
vg2.SRVY_STN_LEN, 
vg2.ELEV_BEG, 
vg2.ELEV_END, 
vg2.GRADE_PERCENT 
from 
RIS.TRPT_SUPERVISOR super, 
RIS.VGRADE2 vg2 
where 
super.LINE_SEG_NBR = vg2.LINE_SEG_NBR 
and super.SUPVR_COST_ID = ':5' 
and super.SUPVR_COST_ID = ':6' 
and abs(vG2.GRADE_PERCENT) >= :7 
and 1=1 
order by LINE_SEG_NBR, BEGMP, TRACK_SDTK_NBR;
TABLE FILE SQLOUT
PRINT *
ON TABLE HOLD AS MYHOLD
END
-RUN


Now report from the HOLD file named MYHOLD -

TABLE FILE MYHOLD
.......

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
November 16, 2006, 10:54 AM
<BillBrockington>
You must add the prefix operator DST. before each field in the PRINT statement. This will cause the SQL code to say select distinct.

TABLE FILE TABLENAME
PRINT
DST.FIELD1
DST.FIELD2
DST.FIELD3
DST.FIELD4
DST.CMPL_NM
WHERE STATEMENTS
END
November 16, 2006, 11:31 AM
BlueZone
Anubha :
Like Tony says, whenever possible, I would recommend that you use the SQL passthru technique to pull your data and then use the power of focus to massage/format/present data as a report.

This way you are working to the strengths of both - SQL (data extraction) and FOCUS(data manipulation). You would get to thoroughly test/tune your SQL first (EXPLAINs, Build indexes, etc) and then let FOCUS do what it does best.
Here is how it could look like -

SQL DB2 (or whatever engine you got)
SELECT
F1
, F2
, SUM(F3)
FROM HLQ.TBLNAME A
WHERE F99 = 'XX'
GROUP BY F1, F2
;
TABLE
ON TABLE HOLD AS H0001
END
-RUN
-*
TABLE FILE H0001
~~~~~~~ (you know the drill) ~~~~~~~
END

Good luck.
Sandeep M.


-------------------------------------------------------------------------------------------------
Blue Cross & Blue Shield of MS
WF.76-10 on (WS2003 + WebSphere) / EDA on z/OS + DB2 + MS-SQL
MRE, BID, Dev. Studio, Self-Service apps & a dash of fun !! Music