× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi all

I have an SQLRPGLE program that we've been running over 2 years - all of a sudden, it is not working right. I wonder what changed - I believe no PTFs were applied last Thursday.

I do used NTEs (nested tables expressions) inside the CTE - I did try making them CTEs, but that didn't fix it - but that doesn't explain the changed behavior

The SQL SELECT statement includes a 3-way self JOIN - here's what the data structure looks like in table SVYQUE (survey questions) -

Reference code (REFCOD) - char(8) - this is a reference that is common to several tables related to invoices.
Question index (QSTIDX) - zoned(3, 0)
Question number (QSTNBR) - zoned(3, 0)
Response text (QSTRDS) - char(60)

The reference code is a unique identifier for an invoice, say, and the others refer to a set of survey questions. This survey (#88) has 3 questions, and question numbers are 10, 20, and 30. There is supposed to be only one of each kind question, but I wonder if we didn't have some kind of duplicates - can't remember, not - but that would be why I used ROW_NUMBER, perhaps.

This has worked fine for over 2 years - then Friday and this morning, it did not handle this right - there are 3 CTEs - Q10 is the REFCOD, ROWNUM, and QSTRDS for question number 10, same for 20 and 30. ROWNUM has always been 1, so far as I know, in these last 2+ years.

Now if I run the CTEs separately, ROWNUM is actually 1 in each - but if JOINed as here, there is no record returned for most values of REFCOD - there was 1 REFCOD for which values were returned.

The desired output is like this -
REFCOD     Reply#1     Reply#2     Reply#3

I have focused on ROWNUM as not matching - but it might be REFCOD - that would be extremely strange, since it is coming from the exact same column in the exact same row in the exact same table.

SELECT q10.refcod, q10.qstrds po#, q20.qstrds wo#,
                    q30.qstrds saddress
              FROM (SELECT refcod, ROW_NUMBER()
                          OVER(ORDER BY refcod, change_ts) rownum,
                            qstrds
                          FROM svyque
                          WHERE qstidx = 88 AND qstnbr = 10) q10
                JOIN (SELECT refcod, ROW_NUMBER()
                          OVER(ORDER BY refcod, change_ts) rownum,
                            qstrds
                          FROM svyque
                          WHERE qstidx = 88 AND qstnbr = 20) q20
                 ON q10.refcod = q20.refcod AND
                     q10.rownum = q20.rownum
                JOIN (SELECT refcod, ROW_NUMBER()
                          OVER(ORDER BY refcod, change_ts) rownum,
                            qstrds
                          FROM svyque
                          WHERE qstidx = 88 AND qstnbr = 30) q30
                 ON q10.refcod = q30.refcod AND
                     q10.rownum = q30.rownum where q10.refcod = 'E8755216';     --  I put the WHERE caluse here for testing individual items - it's not part of the running code.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.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 on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.