Autor Beitrag
bis11
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1247
Erhaltene Danke: 2

Apple Mac OSX 10.11

BeitragVerfasst: Do 31.10.02 13:12 
Hi Leute,

ich habe folgende Abfrage für eine Access-Datenbank :
ausblenden Quelltext
1:
2:
3:
4:
5:
  with DatenModul.ADOQueryAbfrageEingang do begin
    SQL.Clear;  
    SQL.Add('SELECT SUM(ZubehoerMenge) FROM ZubehoerEingang');
    Open;         
  end;


Nun möchte ich das Ergebnis dieser Select-Anweisung in einer Variablen speichern, damit ich mit dem Wert rechnen kann. Wie mache ich das ? Die Suche im forum hat mir zwar einiges gezeigt, aber ich konnte damit nichts anfangen.
neojones
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1206
Erhaltene Danke: 1



BeitragVerfasst: Do 31.10.02 14:47 
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
 
  with DatenModul.ADOQueryAbfrageEingang do begin 
    SQL.Clear;  
    SQL.Add('SELECT SUM(ZubehoerMenge) AS anzahl FROM ZubehoerEingang'); 
    Open;          
    Variable := FieldByName('anzahl').AsFloat;
  end;

_________________
Ha! Es compiliert! Wir können ausliefern!
Alfons-G
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 307

Win XP Prof, Linux, Win 7
D5 Prof, D7 Architect, D2005 Architect, D2007 Architect
BeitragVerfasst: Do 31.10.02 14:51 
:wave:
Als Erstes solst Du unbedingt dem Ergebnis Deiner Select-Anweisung einen definierten Namen zuweisen:SQL.Add('SELECT SUM(ZubehoerMenge) AS SummeMenge FROM ZubehoerEingang');Dann kannst Du mit Menge := DatenModul.ADOQueryAbfrageEingang.Fields[0].AsInteger; alternativ AsFloat, wenn Du nicht nur Ganzzahlen bekommst, das Ergebnis einer Variable des passenden Typs zuweisen.
Du könntest statt Fields[0] auch FieldByName("SummeMenge") verwenden, da die Query nur eine Spalte liefert, ist das aber egal.

:)

_________________
Alfons Grünewald
bis11 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1247
Erhaltene Danke: 2

Apple Mac OSX 10.11

BeitragVerfasst: Do 31.10.02 15:59 
Ich danke euch erstmal für eure Antworten. Die Sachen funktionieren.