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

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
gohjoe
Posts: 7
Joined: Thu 17 Jan 2008 14:35

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

Post by gohjoe » Thu 17 Jan 2008 15:05

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

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 21 Jan 2008 12:57

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;

gohjoe
Posts: 7
Joined: Thu 17 Jan 2008 14:35

Thanks

Post by gohjoe » Tue 22 Jan 2008 10:26

Thanks.

Post Reply