Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Too many args in my complex SQL
Message
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01251397
Message ID:
01251656
Views:
14
Hi Terry,

I doubt it was me because I would point out immediatelly that DELETED() or any other function that can have an alias as a parameter cannot be used in multitable query because it could return unexpected results. You should use SET DELETED ON.

>
>Here was the original code (which you kindly helped with last summer, BTW), which I have now reinstated.
>
>SELECT ET.Operator, ET.Route, ET.Class, ET.Date, ET.RorF, op.Desc as OpDesc, ;
>	Thisform.lmGetServeType( ET.Operator, ET.Route, ET.Date) as ServeType, ;
>	IIF( ET.Route == ET.Mcl_Rte, "    ", ET.Mcl_Rte) as ContrNum, ET.Family, ;
>	SUM( IIF( BETWEEN( ET.date, ldStartCurr, ldEndCurr), ET.Number, 0000000)) AS CurrPass, ;
>	SUM( IIF( BETWEEN( ET.date, ldStartPrev, ldEndPrev), ET.Number, 0000000)) AS PrevPass ;
>  FROM ETMData ET ;
>	JOIN Operator op ;
>	  On 	ET.Operator 	== op.Code ;
>  WHERE ET.Operator 		== lnOpCode ;
>  AND	(   ET.date BETWEEN ldStartCurr and ldEndCurr ;
>  	 OR ET.date BETWEEN ldStartPrev and ldEndPrev) ;
>  AND not DELETED() ;
>  ORDER BY	ET.Operator, OpDesc, ET.Route, ET.Class ;
>  GROUP BY	ET.Mcl_Rte, OpDesc, ET.Operator, ET.Route, ET.Class ;
>  INTO CURSOR csrETMPassengers NOFILTER READWRITE
>
>
>As I said in another message, I was barking up the wrong tree. The start and end dates of the 2 report periods (prev and curr) don't change. The problem with this report is that the value ET.Number is each to be multiplied by a "multiplier", depending on the ET rec's "Class", got from an Operator-Class table
>
>Now these Classes go by operator and date. Sometimes an operator can have the same Class no., but it may have expired, so there'll be a new one. Each of these recs has a start and end date - some being open.
>
>eg
>
>Operator  Class  StartDate  EndDate   Multiplier
>13        0037   --------   31/03/06           2
>13        0037   01/04/06   --------           1
>
>
>FYI the class is to do with bus ticket sales., from an electronic ticket machine (ETM). If a mult. of 2 then it was a return ticket. In the last year all bus journeys for pensioners have been made free by the govt. so this prog is comparing these concessionary fares/sales between similar periods, 2 different years.
>
>Problem is with open-ended dates like above, in the code that works out the no. tickets * mult (Pass 2 - somewhere else on the form), sales for, say op=13, class=0037 are getting totted twice, once for each class, so we get this combo duplicated, one being twice the previous.
>
>I'm trying to trace where this happens, but I'm a bit rusty on this form and so was looking in the wrong place. As it is I STILL haven't found where the dupes are happening.
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform