There has to be a simple reason why my SQL SELECT statement won't parse in A5 - but I can't find it.
I have a complicated 'number of weeks between two dates, except ...' field to include as a field on a report (not my idea). I'm using Access as a backend, and just to make sure that the SQL SELECT statement works as intended, I used a query in the webroot version of the Access programme to develop it. Access produces the field instantly. When I copy and paste the SQL SELECT statement from the Access query into the A5 Grid Query Builder - my machine crashes. I've imported the statement sequentially (ie bit by bit) and it works to a point, then when the loops get too long - it gets overloaded.
I've even deleted the extra 'I' from all the 'If's.' According to my reading, an Access SQL Select statement should work in A5 - but this one doesn't. Perhaps the reason relates to my use of DateSerial(yyyy.mm,dd)? I can't find any suggestion on how to specify dates differently?
I can't see any way of simplifying the SELECT statement - and if it works in Access - it should work in A5.
I don't expect anyone to read through and make any sense of the SQL statement itself - but just in case anyone can see something that A5 obviously doesn't like - it is:
SELECT Cases.CaseName, Cases.ApprovedDate, Cases.CloseDate, IIf( Datediff('ww', Cases.ApprovedDate, Date() ) > 46 , '>40', IIf(Cases.ApprovedDate BETWEEN DateSerial(2012, 1, 23) AND DateSerial(2012, 4, 6) AND CloseDate > DateSerial(2012, 10, 15) , ( DateDiff('ww', Cases.ApprovedDate, Cases.CloseDate) - 6), IIf(Cases.ApprovedDate BETWEEN DateSerial(2012, 1, 23) AND DateSerial(2012, 4, 6) AND Cases.CloseDate BETWEEN DateSerial(2012, 7, 16) AND DateSerial(2012, 10, 2) OR Cases.ApprovedDate BETWEEN DateSerial(2012, 4, 23) AND DateSerial(2012, 6, 30) AND CloseDate > DateSerial(2012, 10, 15) , ( DateDiff('ww', Cases.ApprovedDate, Cases.CloseDate) - 4), IIf(Cases.ApprovedDate BETWEEN DateSerial(2012, 1, 23) AND DateSerial(2012, 4, 6) AND Cases.CloseDate BETWEEN DateSerial(2012, 4, 23) AND DateSerial(2012, 6, 30) OR Cases.ApprovedDate BETWEEN DateSerial(2012, 4, 23) AND DateSerial(2012, 6, 30) AND Cases.CloseDate BETWEEN DateSerial(2012, 7, 16) AND DateSerial(2012, 10, 2) OR Cases.ApprovedDate BETWEEN DateSerial(2012, 7, 16) AND DateSerial(2012, 10, 2) AND Cases.CloseDate > DateSerial(2012, 10, 15) , ( DateDiff('ww', Cases.ApprovedDate, Cases.CloseDate) - 2), IIf([Cases].[ApprovedDate] Between DateSerial(2012,1,23) And DateSerial(2012,4,6) And IsNull([Cases].[Closedate]),(DateDiff('ww',[Cases].[ApprovedDate],Date())-6),IIf([Cases].[ApprovedDate] Between DateSerial(2012,1,23) And DateSerial(2012,4,6) And IsNull([Cases].[Closedate]) Or [Cases].[ApprovedDate] Between DateSerial(2012,4,23) And DateSerial(2012,6,30) And IsNull([Cases].[Closedate]),(DateDiff('ww',[Cases].[ApprovedDate],Date())-4),IIf([Cases].[ApprovedDate] Between DateSerial(2012,1,23) And DateSerial(2012,4,6) And IsNull([Cases].[Closedate]) Or [Cases].[ApprovedDate] Between DateSerial(2012,4,23) And DateSerial(2012,6,30) And IsNull([Cases].[Closedate]) Or [Cases].[ApprovedDate] Between DateSerial(2012,7,16) And DateSerial(2012,10,2) And IsNull([Cases].[Closedate]),(DateDiff('ww',[Cases].[ApprovedDate],Date())-2),( DateDiff('ww', Cases.ApprovedDate, Cases.CloseDate)))) ) ) ) )) AS Duration
FROM RTLBDetails INNER JOIN (Cases INNER JOIN (Schools INNER JOIN CasesSchools ON Schools.SchoolID = CasesSchools.SchoolID) ON Cases.CaseID = CasesSchools.CaseID) ON RTLBDetails.GroupID = Cases.ReferringRTLBID;
Trust me - it produces a great result in Access!
I have a complicated 'number of weeks between two dates, except ...' field to include as a field on a report (not my idea). I'm using Access as a backend, and just to make sure that the SQL SELECT statement works as intended, I used a query in the webroot version of the Access programme to develop it. Access produces the field instantly. When I copy and paste the SQL SELECT statement from the Access query into the A5 Grid Query Builder - my machine crashes. I've imported the statement sequentially (ie bit by bit) and it works to a point, then when the loops get too long - it gets overloaded.
I've even deleted the extra 'I' from all the 'If's.' According to my reading, an Access SQL Select statement should work in A5 - but this one doesn't. Perhaps the reason relates to my use of DateSerial(yyyy.mm,dd)? I can't find any suggestion on how to specify dates differently?
I can't see any way of simplifying the SELECT statement - and if it works in Access - it should work in A5.
I don't expect anyone to read through and make any sense of the SQL statement itself - but just in case anyone can see something that A5 obviously doesn't like - it is:
SELECT Cases.CaseName, Cases.ApprovedDate, Cases.CloseDate, IIf( Datediff('ww', Cases.ApprovedDate, Date() ) > 46 , '>40', IIf(Cases.ApprovedDate BETWEEN DateSerial(2012, 1, 23) AND DateSerial(2012, 4, 6) AND CloseDate > DateSerial(2012, 10, 15) , ( DateDiff('ww', Cases.ApprovedDate, Cases.CloseDate) - 6), IIf(Cases.ApprovedDate BETWEEN DateSerial(2012, 1, 23) AND DateSerial(2012, 4, 6) AND Cases.CloseDate BETWEEN DateSerial(2012, 7, 16) AND DateSerial(2012, 10, 2) OR Cases.ApprovedDate BETWEEN DateSerial(2012, 4, 23) AND DateSerial(2012, 6, 30) AND CloseDate > DateSerial(2012, 10, 15) , ( DateDiff('ww', Cases.ApprovedDate, Cases.CloseDate) - 4), IIf(Cases.ApprovedDate BETWEEN DateSerial(2012, 1, 23) AND DateSerial(2012, 4, 6) AND Cases.CloseDate BETWEEN DateSerial(2012, 4, 23) AND DateSerial(2012, 6, 30) OR Cases.ApprovedDate BETWEEN DateSerial(2012, 4, 23) AND DateSerial(2012, 6, 30) AND Cases.CloseDate BETWEEN DateSerial(2012, 7, 16) AND DateSerial(2012, 10, 2) OR Cases.ApprovedDate BETWEEN DateSerial(2012, 7, 16) AND DateSerial(2012, 10, 2) AND Cases.CloseDate > DateSerial(2012, 10, 15) , ( DateDiff('ww', Cases.ApprovedDate, Cases.CloseDate) - 2), IIf([Cases].[ApprovedDate] Between DateSerial(2012,1,23) And DateSerial(2012,4,6) And IsNull([Cases].[Closedate]),(DateDiff('ww',[Cases].[ApprovedDate],Date())-6),IIf([Cases].[ApprovedDate] Between DateSerial(2012,1,23) And DateSerial(2012,4,6) And IsNull([Cases].[Closedate]) Or [Cases].[ApprovedDate] Between DateSerial(2012,4,23) And DateSerial(2012,6,30) And IsNull([Cases].[Closedate]),(DateDiff('ww',[Cases].[ApprovedDate],Date())-4),IIf([Cases].[ApprovedDate] Between DateSerial(2012,1,23) And DateSerial(2012,4,6) And IsNull([Cases].[Closedate]) Or [Cases].[ApprovedDate] Between DateSerial(2012,4,23) And DateSerial(2012,6,30) And IsNull([Cases].[Closedate]) Or [Cases].[ApprovedDate] Between DateSerial(2012,7,16) And DateSerial(2012,10,2) And IsNull([Cases].[Closedate]),(DateDiff('ww',[Cases].[ApprovedDate],Date())-2),( DateDiff('ww', Cases.ApprovedDate, Cases.CloseDate)))) ) ) ) )) AS Duration
FROM RTLBDetails INNER JOIN (Cases INNER JOIN (Schools INNER JOIN CasesSchools ON Schools.SchoolID = CasesSchools.SchoolID) ON Cases.CaseID = CasesSchools.CaseID) ON RTLBDetails.GroupID = Cases.ReferringRTLBID;
Trust me - it produces a great result in Access!
Comment