Icon View Incident Report

Serious Serious
Reported By: Roy Lambert
Reported On: 10/12/2018
For: Version 2.28 Build 7
# 4697 Sub-Queries Mixed with SELECT Aggregate Expressions Can Result in Improper Evaluation of Sub-Queries

I'm helping Ian out with a query - the first one works but if I change it to the second, it doesn't.

EG the first line of output is

1 0 0.00

but the second query returns

1 0 100.00

its as if with the second query the second SUM(Qry) ALWAYS returns 1 and I don't understand it.

First - works:

SELECT
JobType,
SUM(Qty) AS "Total Units",
COALESCE((SELECT SUM(X.Qty) FROM JobTickets X WHERE X.JobType = JobTickets.JobType AND X.JobCode = 'SVC' RANGE 1 TO 1),0) AS Bounces,
CAST(
100*
(SELECT COALESCE(SUM(P.Qty),0) FROM JobTickets P WHERE P.JobType = JobTickets.JobType AND P.JobCode = 'SVC' )
/
(SELECT COALESCE(SUM(Qty),0) FROM JobTickets  Q WHERE Q.JobType = JobTickets.JobType )
AS NUMERIC(5,2)) AS Pcnt
FROM JobTickets
GROUP BY JobType

Second - doesn't:

SELECT
JobType,
SUM(Qty) AS "Total Units",
COALESCE((SELECT SUM(X.Qty) FROM JobTickets X WHERE X.JobType = JobTickets.JobType AND X.JobCode = 'SVC' RANGE 1 TO 1),0) AS Bounces,
CAST(
100*
(SELECT COALESCE(SUM(P.Qty),0) FROM JobTickets P WHERE P.JobType = JobTickets.JobType AND P.JobCode = 'SVC' )
/
SUM(Qty)  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
AS NUMERIC(5,2)) AS Pcnt
FROM JobTickets
GROUP BY JobType



Comments Comments and Workarounds
The problem was that the sub-query was not getting broken out as a separate sub-expression for the SELECT column, thus resulting in the sub-query getting evaluated *again* during the *result row evaluation* where the final SELECT column expressions are evaluated.


Resolution Resolution
Fixed Problem on 10/23/2018 in version 2.29 build 1


Products Affected Products Affected
ElevateDB Additional Software and Utilities
ElevateDB DAC Client-Server
ElevateDB DAC Client-Server with Source
ElevateDB DAC Standard
ElevateDB DAC Standard with Source
ElevateDB DAC Trial
ElevateDB LCL Standard with Source
ElevateDB PHP Standard
ElevateDB PHP Standard with Source
ElevateDB PHP Trial
ElevateDB VCL Client-Server
ElevateDB VCL Client-Server with Source
ElevateDB VCL Standard
ElevateDB VCL Standard with Source
ElevateDB VCL Trial

Image