而且
s:='select 账户类别,sum(收入金额)as 收入总额 from Income where 账户类别='+QuotedStr(bsSkinDBEdit1.Text)+' group by 账户类别';
s:='select 账户类别,sum(支出金额)as 支出总额 from expense where 账户类别='+QuotedStr(bsSkinDBEdit1.Text)+' group by 账户类别';
这两个语句可以一个SQL中进行的,直接算出来账户余额了
select a.账户类别,sum(a.收入金额) as 收入总额,su…
[/Quote]
谢谢高手提点,学习了
而且
s:='select 账户类别,sum(收入金额)as 收入总额 from Income where 账户类别='+QuotedStr(bsSkinDBEdit1.Text)+' group by 账户类别';
s:='select 账户类别,sum(支出金额)as 支出总额 from expense where 账户类别='+QuotedStr(bsSkinDBEdit1.Text)+' group by 账户类别';
这两个语句可以一个SQL中进行的,直接算出来账户余额了
select a.账户类别,sum(a.收入金额) as 收入总额,sum(b.支出金额)as 支出总额,
sum(a.收入金额)-sum(b.支出金额) as 账户余额
from Income a,expense b
where a.账户类别=b.账户类别
group by a.账户类别
注意可能要用到外联接
procedure TFrmAccountType.bsSkinButton6Click(Sender: TObject);
var
Income,Expense,Balance:Currency;
s:string;
begin
s:='select 账户类别,sum(收入金额)as 收入总额 from Income where 账户类别='+QuotedStr(bsSkinDBEdit1.Text)+' group by 账户类别';
with Query2 do
begin
Close;
SQL.clear;
SQL.add(s);
try
open;
except
execsql;
end;
end;
Income:=Query2.Fields[1].AsCurrency;
with Table1 do
begin
edit;
fieldValues['收入总额']:=Income;
post;
end;
s:='select 账户类别,sum(支出金额)as 支出总额 from expense where 账户类别='+QuotedStr(bsSkinDBEdit1.Text)+' group by 账户类别';
with Query2 do
begin
Close;
SQL.clear;
SQL.add(s);
try
open;
except
execsql;
end;
end;
Expense:=Query2.Fields[1].AsCurrency;
with Table1 do
begin
edit;
fieldValues['支出总额']:=Expense;
post;
end;
Balance:=StrToCurr(IncomeSum.Text)-StrToCurr(ExpenseSum.Text);
with Table1 do
begin
edit;
fieldValues['账户余额']:=Balance;
post;
end;
end;