MIDRANGE dot COM Mailing List Archive



Home » MIDRANGE-L » October 2012

Re: Joining to a join in SQL?



fixed

If they are SQL views then yes you can create a view over it

For example:
CREATE VIEW COGNOSVIEW/ACTBALRCD AS (
SELECT BLACT1,C.STORENUMBER AS BLACT2,C.COSTCENTER AS BLACT3,
BLACT4,BALTYP,YEAR,PERIOD,BALNCE
FROM LIBD4201/IASCP032 A
LEFT JOIN WEBBUDGET/WEBASSIGN B
ON (TRIM(A.BLACT2) || TRIM(A.BLACT3)) =
TRIM(B.STORECODE)
LEFT JOIN WEBBUDGET/WEBASSIGN C
ON TRIM(B.ROLLUP) = TRIM(C.STORECODE)
WHERE BALTYP = '*ACTUAL'
AND BLACT1 BETWEEN '41000' AND '89999'
AND COMPNO = 1 AND PERIOD BETWEEN 1 AND 12
AND YEAR>=(YEAR(CURRENT DATE)-1)
AND (C.STORENUMBER IS NOT NULL)
AND (C.COSTCENTER IS NOT NULL)
) RCDFMT ACTBALRCDR;

CREATE VIEW COGNOSVIEW/ACTUAL12 AS (
SELECT A.*, CAST( ( A.YEAR * 100 ) + PERIOD AS INT ) AS PER_YEAR
FROM COGNOSVIEW/ACTBALRCD A
WHERE CAST( ( "YEAR" * 100 ) + PERIOD AS INT )
BETWEEN
CAST( DIGITS( YEAR( CURRENT_DATE - 1 YEAR ) ) AS INT ) * 100
-- + CAST( DIGITS( MONTH( CURRENT_DATE - 1 YEAR ) + 1 ) AS INT )
+ CAST( DIGITS( MONTH( CURRENT_DATE - 1 YEAR ) ) AS INT )
AND
CAST( DIGITS( YEAR( CURRENT_DATE ) ) AS INT )
* 100 + CAST( DIGITS( MONTH( CURRENT_DATE ) - 1 ) AS INT )
) RCDFMT ACT12R;


Thanks,
Tommy Holden



From: James Lampert <jamesl@xxxxxxxxxxxxxxxxx>
To: Midrange Systems Technical Discussion <midrange-l@xxxxxxxxxxxx>,
Date: 10/02/2012 11:35 AM
Subject: Joining to a join in SQL?
Sent by: midrange-l-bounces@xxxxxxxxxxxx



Consider this scenario:

You have a group of PFs, which in turn have a few LFs on them. You are
mainly doing native/RLA processing on them, but also some SQL, both
views and ad-hoc queries, all of which can potentially involve SQL
joins, and most of which involve programmatically-created SQL.

So far, so good.

But now, let's change the scenario:

Suppose you want to replace the PFs and LFs with join-logicals (or SQL
join-views), tying directly into data in other libraries.

But what about the aforementioned SQL views and queries, that involve
joins? Do they have to be built from the raw PFs? Or can they be built
on top of the existing joins?

--
JHHL





Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2014 by MIDRANGE dot COM and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact