Autor Beitrag
D. Annies
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Do 06.10.11 14:27 
Hi, Delpher,

ich will ein Geburtsdatum der Form tt.mm.jjjj, das (leider) als String in einer Tabelle vorliegt, auf "heute Geburtstag" prüfen,
d.h. der Tag und der Monat müssen stimmen. Wie lautet denn dafür ein SQL-Befehl?

Ich habe zwei StringVariablen Tg und Mo : Integer deklariert.
Brauche ich da Parameter? Hilft LIKE da iwi weiter?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
format('select Name, Vorname, Klasse, Gebdat, Telefon from "%s" ' +
                            'where  ????? = :MONAT and ????? = :TAG ' +
                            'order by Name, Vorname, Klasse', [TbName]);
      Qx.ParamByName('Tag').AsString := inttostr(Tg);
      Qx.ParamByName('Monat').AsString := inttostr(Mo);


Vielen Dank für eine Hilfe,
Detlef

_________________
ut vires desint, tamen est laudanda voluntas
guinnes
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 182
Erhaltene Danke: 14



BeitragVerfasst: Do 06.10.11 14:34 
In MySQL gibts die Stringfunktionen Left, Mid, und right, damit geht es definitiv

Für diesen Beitrag haben gedankt: D. Annies
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Do 06.10.11 14:45 
guinness hat schon Recht, aber da sind auch noch viele Dinge zu beachten. Z.B.: Sind Tag und Monat immer 2-stellig?

Ich arbeite mit Oracle und dort gibt es die Möglichkeit mit der Funktion "to_date" einen String in ein Kalenderdatum zu wandeln. Wenn man dazu noch die Funktionen "Day" und "Month" auf das Datum anwendet, sollte es auch funktionieren.

Für diesen Beitrag haben gedankt: D. Annies
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Do 06.10.11 15:06 
1. to_day wird nicht erkannt.

2. left auch nicht: (?)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
qx.SQL.Text := format('select Name, Vorname, Klasse, Gebdat, Telefon from "%s" ' +
                            'where left(gebdat,2) = :MONAT and Mid(gebdat,4,2) = :TAG ' +
                            'order by Name, Vorname, Klasse', [TbName]);
      Qx.ParamByName('Tag').AsString := inttostr(Tg);
      Qx.ParamByName('Monat').AsString := inttostr(Mo);

oder habe ich es falsch benutzt?

cu, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Do 06.10.11 15:09 
user profile iconD. Annies hat folgendes geschrieben Zum zitierten Posting springen:
1. to_day wird nicht erkannt.

In Oracle heißt es to_date. iirc heißte es bei Standard-SQL nur "date".
to_day habe ich nirgendwo geschrieben. :wink:
guinnes
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 182
Erhaltene Danke: 14



BeitragVerfasst: Do 06.10.11 15:17 
user profile iconD. Annies hat folgendes geschrieben Zum zitierten Posting springen:

ausblenden Delphi-Quelltext
1:
2:
      Qx.ParamByName('Tag').AsString := inttostr(Tg);
      Qx.ParamByName('Monat').AsString := inttostr(Mo);

Denke daran, daß dabei u.U. ein einstelliges Datum ( Tag bzw Monat ) bei rauskommt
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Do 06.10.11 15:19 
Entschuldige meinen Schreibfehler.

Left scheint doch erkannt zu werden, aber nicht mid:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
qx.SQL.Text := format('select Name, Vorname, Klasse, Gebdat, Telefon from "%s" ' +
                            'where left(gebdat,2) = :MONAT and mid(gebdat, 4,2) = :TAG ' +
                            'order by Name, Vorname, Klasse', [TbName]);
      Qx.ParamByName('Tag').AsString := inttostr(Tg);
      Qx.ParamByName('Monat').AsString := inttostr(Mo);


Habe ich etwas falsch geschrieben?

_________________
ut vires desint, tamen est laudanda voluntas
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Do 06.10.11 16:58 
Na, ja, so geht es:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
TAG_MON := inttostr(Tg) +'.' + inttostr(Mo);
  if TbSchueler.Fieldbyname('gebdat').DataType = ftString then
  begin
    showmessage('lets go');
    qx.Close;
      qx.SQL.Text := format('select Name, Vorname, Klasse, Gebdat, Telefon from "%s" ' +
                            'where left(gebdat,5) = :TAG_MON ' +
                            'order by Name, Vorname, Klasse', [TbName]);
      Qx.ParamByName('Tag_Mon').AsString := Tag_Mon;
    qx.Open;
;

bis denne,
Detlef

_________________
ut vires desint, tamen est laudanda voluntas