Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select SUM and calculate sum() different values
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00382827
Message ID:
00383002
Views:
18
>Has anyone come across these commands that return different results with the same query condition
>
>CODE SECTION
>-----------------
>rdates(1) = a date defined by the user
>rdates(2) = calculated date based on a rule - which is always the lesser of the two dates
>
>* sum the values between these dates
>CALCULATE SUM(hrs_driving+hrs_onduty) TO Results(1) ;
> FOR logs.employee_code = THISFORM.EMPLOYEE_CODE1.Text1.VALUE ;
> AND BETWEEN(logs.txdate,rdates(2),rdates(1))
>
>* sum the values between these dates
>SELECT SUM(hrs_driving+hrs_onduty) AS 'results1' ;
> FROM logs!logs INTO CURSOR 'test1' ;
> WHERE logs.employee_code = THISFORM.EMPLOYEE_CODE1.Text1.VALUE ;
> AND BETWEEN(logs.txdate,rdates(2),rdates(1))
>-----------------
>The results are :
> Calculate sum() = 73.5
> SQL sum() = 63.00
>
>IF ANY ONE CAN SPOT THE PROBLEM PLEASE LET ME KNOW...

Calculate Sum works with updated data while SQL Select works with data directly from the disk. In SQL Select, its reference is not from your currently opened table, so whatever current changes you have couldn't be included in the resultset.

I also noticed that your SQL Select don't have a GROUP BY which is required to come up with supposedly the same result.
JESS S. BANAGA
Project Leader - SDD division
...shifting from VFP to C#.Net

CHARISMA simply means: "Be more concerned about making others feel good about themselves than you are in making them feel good about you."
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform