Autor Beitrag
ibh_compucat
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 130

Win 2000, Win 8.1
D6, Ent. XE5 Ent.
BeitragVerfasst: Mo 26.05.08 10:42 
Hallo,

Wie kann ich über eine Query einen Zeitraum abfragen (in einer Access Tabelle), bei dem ich nicht nur das Datum sondern auch die Zeit abfrage, nach Datum sähe das so aus (DATUMSTEMPEL ist ein TDateTime Feld in Tabelle):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
      s := 'Select * FROM Tabelle ' +
           'where DATUMSTEMPEL Between ' + #39 +
           '23.05.2008' + #39 +
           ' AND ' + #39 + '25.05.2008' + #39;
      try
        Form1.ADOQuery1.Close;
        Form1.ADOQuery1.SQL.Text := s; 
        Form1.ADOQuery1.Open;
      except
      end;

aber wie kann ich abfragen, welche Datensätze in der Zeit zwischen dem 23.05.2008 12:30:00 und dem 25.05.2008 9:00:00 liegen?

Gruß ibh_compucat

Moderiert von user profile iconNarses: Delphi-Tags hinzugefügt
Moderiert von user profile iconNarses: Topic aus Sonstiges (Delphi) verschoben am Mo 26.05.2008 um 10:55

_________________
Was du nicht begreifst, kannst du nicht verlernen!
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mo 26.05.08 11:31 
Verwende (SQL-)Parameter

_________________
Markus Kinzler.
ibh_compucat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 130

Win 2000, Win 8.1
D6, Ent. XE5 Ent.
BeitragVerfasst: Mo 26.05.08 11:57 
Hallo Markus,

ich habe inzwischen ausprobiert:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
    HS := 'SELECT * FROM TABELLE ' +
          'WHERE DATUMSTEMPEL BETWEEN ' +
          FormatDateTime('"#"mm"/"dd"/"yyyy hh:nn:ss"#"', Startpunkt) + ' AND ' +
          FormatDateTime('"#"mm"/"dd"/"yyyy hh:nn:ss"#"', Now);
    Form1.ADOQuery1.SQL.Text := HS;
    Form1.ADOQuery1.Open;


aber da meckert er auch.

mit Parametern sähe das so aus ??????

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
    HS := 'SELECT * FROM TABELLE ' +
          'WHERE DATUMSTEMPEL BETWEEN ' +
          ':Startzeit AND :StoppZeit';

    Form1.ADOQuery1.ParamByName('Startzeit').ASDateTime := Startpunkt;
    Form1.ADOQuery1.ParamByName('Stoppzeit').ASDateTime := Now;
    Form1.ADOQuery1.Open;


Gruß ibh_compucat

Moderiert von user profile iconUGrohne: Beitragsformatierung überarbeitet.

_________________
Was du nicht begreifst, kannst du nicht verlernen!
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mo 26.05.08 12:13 
ausblenden Delphi-Quelltext
1:
ADOQuery1.Parameter.ParamByName('Startzeit').Value := Startpunkt;					

_________________
Markus Kinzler.
ibh_compucat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 130

Win 2000, Win 8.1
D6, Ent. XE5 Ent.
BeitragVerfasst: Mo 26.05.08 12:20 
Danke Markus, das wars!

Gruß ibh_compucat

_________________
Was du nicht begreifst, kannst du nicht verlernen!
ibh_compucat Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 130

Win 2000, Win 8.1
D6, Ent. XE5 Ent.
BeitragVerfasst: Mo 26.05.08 21:05 
Hallo,

ich hatte mich zufrüh gefreut, keiner meckert mehr, aber die Abfrage liefert leider alle Datensätze und nicht nur die in dem vorgegebenen Zeitraum. Hat jemand eine Idee?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
HS := 'SELECT * FROM TABELLE ' + 
      'WHERE DATUMSTEMPEL BETWEEN ' + 
      ':Startzeit AND :StoppZeit ' +
      'ORDER BY DATUMSTEMPEL'

Form1.ADOQuery1.ParamByName('Startzeit').Value := Startpunkt; 
Form1.ADOQuery1.ParamByName('Stoppzeit').Value := Now; 
Form1.ADOQuery1.Open;


Gruß ibh_compucat

_________________
Was du nicht begreifst, kannst du nicht verlernen!