Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Surely this can be one select statement??
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01651131
Message ID:
01651141
Views:
79
>of course - derived tables - thanks Naomi!
>

If this is really SQL Server, you can make it cleaner and easier to read with CTEs.
WITH curHold_1 AS
(SELECT Customer.Customer_id, Customer.Customer_name, Visits.visit_date,;
  Visits.location_id, Visits.Visits_id, 0 AS vcount;
 FROM ;
     hpmg!Customer ;
    LEFT OUTER JOIN hpmg!Visits ;
   ON  Customer.Customer_id = Visits.Customer_id;
 WHERE  YEAR(Visits.visit_date) = ( ?lnYear)),

curHold_2 AS
( SELECT Customer.Customer_id, Visits.visit_date, Visits.location_id,;
  COUNT(*) AS vcount;
 FROM ;
     hpmg!Customer ;
    LEFT OUTER JOIN hpmg!Visits ;
   ON  Customer.Customer_id = Visits.Customer_id;
 WHERE  YEAR(Visits.visit_date) = ( 2015 );
 GROUP BY Customer.Customer_id, Visits.visit_date, Visits.location_id;
 HAVING  ( vcount ) > ( 1 ))

 SELECT curHold_1.Customer_id, curHold_1.Customer_name, curHold_1.Visits_id,;
  curHold_1.visit_date, curHold_1.location_id;
 FROM ;
     curHold_1 ;
    INNER JOIN curHold_2 ;
   ON  curHold_1.Customer_id = curHold_2.Customer_id;
 WHERE (  curHold_1.Customer_id = curHold_2.Customer_id;
   AND  curHold_1.visit_date = curHold_2.visit_date );
   AND  curHold_1.location_id = curHold_2.location_id
Note that I didn't read the code beyond what's needed to do a brute force conversion, so there might be additional simplifications.

Tamar
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform