SQLServer database proc
receives a single parameter that is the enrollment of the face and returns the balance.
SQL Command:
SELECT SUM(CASE Fl_Credito WHEN 1 THEN Vl_Movimento ELSE 0 END) - SUM(CASE Fl_Credito WHEN 0 THEN Vl_Movimento ELSE 0 END)
AS Vl_Saldo
FROM tb_MOTOQUEIRO_MOVIMENTO
WHERE NR_MATRICULA = @PIntMatricula
Calling on Delphi:
with DmBusca.cdsMotoSaldo do
begin
close;
Params[0].AsInteger := StrToInt(edtMATRICULA.Text);
Open;
edtSaldo.Text := FloatToStr(FieldByName('vl_saldo').AsFloat);
end;