thendrickson
Programmer
I am very new with DB2.
I have a pass through query from Access to a DB2 database that seems to run forever (or until the ODBC timeout if set)
If I set the ODBC time out to 0 in Access (never tiems out) the query runs at leat 30 minutes before we killed it.
I am afraid I do not understand the query.
I am posting the whole query, but what I totally do not understand is the 4th line "Select 5".
I find similar in several other queries (different numbers)
which "work fine" according to the end user.
If someone has the time to look over the query and give me some ideas where to start, I would appreciate it.
INSERT INTO M5T1 (METRICID, DTE214, ENDDAYOFWEEK, DAYS214, CSTNO, ORDNO, ORDTYP, STATE, REQDTE, CSTCLS, DAYSREQDTE, TRANSITDAYS, GROSSDAYS, NETDAYS, ONTIME)
SELECT 5, H.*, I.NETDAYS,
CASE WHEN (I.NETDAYS=0) THEN 1 ELSE 0
END
AS ONTIME
FROM (
SELECT E.DTE214, E.ENDDAYOFWEEK, E.DAYS214, F.* ,
( DAYS214-TRANSITDAYS-DAYSREQDTE ) AS GROSS
FROM (
SELECT ORDNO, DTE214, DAYOFWEEK(DTE214) AS ENDDAYOFWEEK, DAYS(DTE214) AS DAYS214
FROM (
SELECT POD.ORDNO, CAST(POD.DATE214 AS DATE ) AS DTE214
FROM EDILIB.SC214 POD
) A ) E,
(
SELECT C.*, T.TRANSITDAYS
FROM (
SELECT A.*, B.CSTCLS, DAYS(REQDTECHAR) AS DAYSREQDTE
FROM
(
SELECT O.CSTNO, O.ORDNO, O.ORDTYP, O.STATE,
CASE
WHEN REQDTE > 99999 THEN '20' || SUBSTRING ( CAST(REQDTE AS CHAR(6)) ,5,2) || '-' || SUBSTRING ( CAST(REQDTE AS CHAR(6)) ,1,2) || '-' || SUBSTRING ( CAST(REQDTE AS CHAR(6)) ,3,2)
ELSE '20' || SUBSTRING ( CAST(REQDTE AS CHAR(6)) ,4,2) || '-0' || SUBSTRING ( CAST(REQDTE AS CHAR(6)) ,1,1) || '-' || SUBSTRING ( CAST(REQDTE AS CHAR(6)) ,2,2)
END AS REQDTECHAR
FROM CCSDTA.DOPORDM0 O , COTYLIB.SCORDLOG L
WHERE O.ORDNO = L.SCORDERNO
AND ( L.SCNEWSTAT = '7'
AND L.SCLGDATE >= (SELECT MONBEGDTE FROM SCORECARD.SCDATES WHERE ACTIVE<>0 )
AND L.SCLGDATE <= (SELECT MONENDDTE FROM SCORECARD.SCDATES WHERE ACTIVE<>0) )
) A,
(SELECT DISTINCT CSTCLS, CSTNO FROM CCSDTA.DOPCMST0) B
WHERE A.CSTNO = B.CSTNO
) C, SCTRANSIT T
WHERE C.STATE = T.STATE
) F
WHERE E.ORDNO = F.ORDNO
) H, SCORECARD.SCNETDAYS I
WHERE H.GROSS = I.GROSSDAYS
AND H.ENDDAYOFWEEK = I.ENDDAYOFWEEK
I have a pass through query from Access to a DB2 database that seems to run forever (or until the ODBC timeout if set)
If I set the ODBC time out to 0 in Access (never tiems out) the query runs at leat 30 minutes before we killed it.
I am afraid I do not understand the query.
I am posting the whole query, but what I totally do not understand is the 4th line "Select 5".
I find similar in several other queries (different numbers)
which "work fine" according to the end user.
If someone has the time to look over the query and give me some ideas where to start, I would appreciate it.
INSERT INTO M5T1 (METRICID, DTE214, ENDDAYOFWEEK, DAYS214, CSTNO, ORDNO, ORDTYP, STATE, REQDTE, CSTCLS, DAYSREQDTE, TRANSITDAYS, GROSSDAYS, NETDAYS, ONTIME)
SELECT 5, H.*, I.NETDAYS,
CASE WHEN (I.NETDAYS=0) THEN 1 ELSE 0
END
AS ONTIME
FROM (
SELECT E.DTE214, E.ENDDAYOFWEEK, E.DAYS214, F.* ,
( DAYS214-TRANSITDAYS-DAYSREQDTE ) AS GROSS
FROM (
SELECT ORDNO, DTE214, DAYOFWEEK(DTE214) AS ENDDAYOFWEEK, DAYS(DTE214) AS DAYS214
FROM (
SELECT POD.ORDNO, CAST(POD.DATE214 AS DATE ) AS DTE214
FROM EDILIB.SC214 POD
) A ) E,
(
SELECT C.*, T.TRANSITDAYS
FROM (
SELECT A.*, B.CSTCLS, DAYS(REQDTECHAR) AS DAYSREQDTE
FROM
(
SELECT O.CSTNO, O.ORDNO, O.ORDTYP, O.STATE,
CASE
WHEN REQDTE > 99999 THEN '20' || SUBSTRING ( CAST(REQDTE AS CHAR(6)) ,5,2) || '-' || SUBSTRING ( CAST(REQDTE AS CHAR(6)) ,1,2) || '-' || SUBSTRING ( CAST(REQDTE AS CHAR(6)) ,3,2)
ELSE '20' || SUBSTRING ( CAST(REQDTE AS CHAR(6)) ,4,2) || '-0' || SUBSTRING ( CAST(REQDTE AS CHAR(6)) ,1,1) || '-' || SUBSTRING ( CAST(REQDTE AS CHAR(6)) ,2,2)
END AS REQDTECHAR
FROM CCSDTA.DOPORDM0 O , COTYLIB.SCORDLOG L
WHERE O.ORDNO = L.SCORDERNO
AND ( L.SCNEWSTAT = '7'
AND L.SCLGDATE >= (SELECT MONBEGDTE FROM SCORECARD.SCDATES WHERE ACTIVE<>0 )
AND L.SCLGDATE <= (SELECT MONENDDTE FROM SCORECARD.SCDATES WHERE ACTIVE<>0) )
) A,
(SELECT DISTINCT CSTCLS, CSTNO FROM CCSDTA.DOPCMST0) B
WHERE A.CSTNO = B.CSTNO
) C, SCTRANSIT T
WHERE C.STATE = T.STATE
) F
WHERE E.ORDNO = F.ORDNO
) H, SCORECARD.SCNETDAYS I
WHERE H.GROSS = I.GROSSDAYS
AND H.ENDDAYOFWEEK = I.ENDDAYOFWEEK