Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL changed its mind again
Message
From
28/07/2006 18:15:18
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
General information
Forum:
Visual FoxPro
Category:
Visual FoxExpress
Miscellaneous
Thread ID:
01141384
Message ID:
01141405
Views:
16
>The following code was happily and successfully selecting data for just the chosen operator, now its gone back to selecting all operators (or damn near all). I don't know what I've done to make it change its mind.
>
>Any ideas?
>
>
>SELECT ET.Operator, ET.Route, ET.Class, ET.Date, ET.RorF, op.Desc as OpDesc, RF1.ServType, ;
>  IIF( ET.Route == ET.Mcl_Rte, "    ", ET.Mcl_Rte) as ContrNum, ;
>  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 ;
>    JOIN RF1 ;
>	On  ET.Operator == RF1.Operator ;
>	and ET.Route    == RF1.ERoute ;
>  WHERE op.Code	       == lnOpCode ;
>  And	(   ET.date BETWEEN ldStartCurr and ldEndCurr ;
>  	 OR ET.date BETWEEN ldStartPrev and ldEndPrev) ;
>  GROUP BY ET.Mcl_Rte, ET.Operator, ET.Route, ET.Class ;
>  ORDER BY ET.Operator, ET.Route, ET.Class ;
>  INTO CURSOR csrETMPassengers NOFILTER
>
>
Terry,
In cases like that I modify SQL a bit as test to see where does that data come from:
SELECT ET.Operator, ;
 et.date,;
 between(ET.date,m.ldStartCurr,m.ldEndCurr) as CurrPass,;
 between(ET.date,m.ldStartPrev,m.ldEndPrev) as PrevPass,;
 m.ldStartCurr as StartCur,;
 m.ldEndCurr as EndCur, ;
 m.ldStartPrev as StartPre, ;
 m.ldEndPrev as EndPre, ;
 op.Code, m.lnOpCode as OpCode ;
  FROM ETMData ET ;
    JOIN Operator op on ET.Operator  == op.Code ;
    JOIN RF1 ;
	On  ET.Operator == RF1.Operator ;
	and ET.Route    == RF1.ERoute ;
  WHERE op.Code	       == m.lnOpCode ;
  And	(   ET.date BETWEEN m.ldStartCurr and m.ldEndCurr ;
  	 OR ET.date BETWEEN m.ldStartPrev and m.ldEndPrev) ;
  ORDER BY ET.Operator, ET.Route, ET.Class
It sometimes helps to see what I'm overlooking.
It looks like if an operator is not working for 2 days at most and those date ranges cover 3 consecutive days all would have a match leaving being eligible to only opcode.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform