Page 1 of 1

How to obtain a numeric sum value from a MyDac component?

Posted: Thu 17 Jan 2008 15:05
by gohjoe
Ok, I got a table that looks like this:

Month WorkerID Salary
Jan JAMES 950.50
Feb JAMES 880.00
Mar JAMES 700.00
Jan PETER 1200.50
Feb PETER 1280.00
Mar PETER 1150.00
Jan HELEN 885.70
Feb HELEN 790.40
Mar HELEN 690.80

Suppose I want to obtain the sum total of Helen's Salary, how shall I go about this? I want to pass this sum value to delphi variable. Do I use a MyQuery component with a SQL like 'Select Sum from WorkerID = HELEN'? Or is there another way to go about this? :D

Posted: Mon 21 Jan 2008 12:57
by Dimon
Yes, you should use a TMyQuery component with a SQL statement like 'select sum(Salary) from table_name where WorkerID = 'HELEN''.
For getting this value to sum variable in your program, use the next code:

Code: Select all

  sum := MyQuery1.Fields[0].AsInteger;

Thanks

Posted: Tue 22 Jan 2008 10:26
by gohjoe
Thanks.