Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2015
    Posts
    1

    Unanswered: SQL0104 - Token <END-OF-STATEMENT> was not valid on this select within a select

    Am I completely missing something here. The first query below works fine for me. But when I add another SELECT around it, I get the error. Is this not possible with DB2? Help!! Thanks!!

    SELECT FLOAT(SUM(FIALLO-FIORDS))/FLOAT(SUM(FIALLO)) AS mfr, SUM(0) AS yfr, SUM(0) AS pfr
    FROM F5711
    WHERE SDADDJ >= 115152 AND SDADDJ < 115182
    AND brand <> 'V'
    UNION
    SELECT SUM(0), FLOAT(SUM(FIALLO-FIORDS))/FLOAT(SUM(FIALLO)), SUM(0)
    FROM F5711
    WHERE SDADDJ >= 115001 AND SDADDJ < 116001
    AND brand <> 'V'
    UNION
    SELECT SUM(0), SUM(0), FLOAT(SUM(FIALLO-FIORDS))/FLOAT(SUM(FIALLO))
    FROM F5711
    WHERE SDADDJ >= 114001 AND SDADDJ < 115001
    AND brand <> 'V'

    SELECT SUM(mfr), SUM(yfr), SUM(pfr)
    FROM (
    SELECT FLOAT(SUM(FIALLO-FIORDS))/FLOAT(SUM(FIALLO)) AS mfr, SUM(0) AS yfr, SUM(0) AS pfr
    FROM F5711
    WHERE SDADDJ >= 115152 AND SDADDJ < 115182
    AND brand <> 'V'
    UNION
    SELECT SUM(0), FLOAT(SUM(FIALLO-FIORDS))/FLOAT(SUM(FIALLO)), SUM(0)
    FROM F5711
    WHERE SDADDJ >= 115001 AND SDADDJ < 116001
    AND brand <> 'V'
    UNION
    SELECT SUM(0), SUM(0), FLOAT(SUM(FIALLO-FIORDS))/FLOAT(SUM(FIALLO))
    FROM F5711
    WHERE SDADDJ >= 114001 AND SDADDJ < 115001
    AND brand <> 'V'
    )

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Check the documentation for your version for the correct syntax to do this. You probably want to use a Common-Table-Expression.

    Andy

  3. #3
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Some DB2 versions still require a correlation clause after a subselect:

    Code:
    select whatever from (
      select something from somewhere
    ) AS t
    ---
    "It does not work" is not a valid problem statement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •