Autor Beitrag
TimHa
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 88



BeitragVerfasst: So 26.03.06 19:21 
Hallo zusammen!

Ich versuche einen SQL Code zu schreiben mit dem sich ein Anwender Daten aus einem bestimmten Jahr angucken kann. Bis jetzt sieht das so aus:

ausblenden Quelltext
1:
2:
3:
select *
from rechnung
where year(datum) = :eingabejahr;


Leider funktioniert das mit year(datum) in Paradox 7 nicht. Wenn ich mich recht erinnere klappt es so unter Access. Wie löse ich das Problem?
In der Tabelle Rechnung gibt es ein Feld Datum vom Typ Datum.

Wie gesagt der Anwender soll ein Jahr eingeben und dann Daten aus diesem Jahr erhalten...

Danke!

Tim
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: So 26.03.06 19:47 
Das YEAR() ist iegendlich nur eine Erfindug von MySQL. Das ist soviel ich weiss kein gültiger SQL Standartbefehl.

Probier mal EXTRACT(YEAR FROM datum)

_________________
In the beginning was the word.
And the word was content-type: text/plain.
TimHa Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 88



BeitragVerfasst: So 26.03.06 20:42 
Ich habe den SQL Code abgeändert. Sieht jetzt so aus:
ausblenden Quelltext
1:
2:
3:
select *
from rechnung
where extract (year from datum) = :eingabejahr;

Leider kommt folgende Fehlermeldung: Keine Übereinstimmung der Typen im Ausdruck.
Irgendwie erscheint mir der Code auch nicht logisch... soll aber nicht viel heißen. :)

Im Endeffekt soll die SQL Abfrage folgendes machen. Der User tippt ein Jahr ein. Sie SQL Abfrage zählt dann die Datensätze und gibt sie in einer Spalte aus. Es soll auch der geringste Rechnungsbetrag, der größte Rechnungsbetrag und ein Durschnitt ausgegeben werden.

In Access habe ich das mal mit Count, AVG, MIN und MAX gemacht. Leider klappt das hier nicht. Wie muss ich es lösen?

Tim
raiguen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 374

WIN 2000prof, WIN XP prof
D7EP, MSSQL, ABSDB
BeitragVerfasst: Mo 27.03.06 09:27 
user profile iconTimHa hat folgendes geschrieben:
Ich habe den SQL Code abgeändert. Sieht jetzt so aus:
ausblenden Quelltext
1:
2:
3:
select *
from rechnung
where extract (year from datum) = :eingabejahr;

Leider kommt folgende Fehlermeldung: Keine Übereinstimmung der Typen im Ausdruck.
Irgendwie erscheint mir der Code auch nicht logisch... soll aber nicht viel heißen. :)
...

Du wirst den Parameter wahrscheinlich als String übergeben haben, erwartet wird ein IntegerWert ;-)


user profile iconTimHa hat folgendes geschrieben:
In Access habe ich das mal mit Count, AVG, MIN und MAX gemacht. Leider klappt das hier nicht. Wie muss ich es lösen?

So zum Beispiel:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
...
SELECT COUNT(rechnungsbetrag) AS Anzahl,
       MIN(rechnungsbetrag) AS Minimum,
       MAX(rechnungsbetrag) AS Maximum,
       AVG(rechnungsbetrag) AS Durchschnitt,
       SUM(rechnungsbetrag) AS Gesamt
FROM rechnung
WHERE EXTRACT(YEAR FROM datum)=:eingabejahr


Rainer
TimHa Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 88



BeitragVerfasst: Mo 27.03.06 14:04 
Hi Rainer!

Danke für deine Hilfe, es hat alles wunderbar geklappt. :)

Eine kurze Frage noch: Wenn ich aus den neu entstandenen Werten einen Bericht erstellen möchte, wie greife ich dann auf diese Werte zu?

formular.query.durchschnitt oder muss ich das anders regeln?

Tim
Ramon
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 107

WIN7
D6 Prof, D7 Prof, D 2009
BeitragVerfasst: Mo 27.03.06 14:25 
Zum Beispiel: formular.query.fieldbyname('durchschnitt ').asInteger;

Moderiert von user profile iconmatze: Delphi-Tags hinzugefügt
raiguen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 374

WIN 2000prof, WIN XP prof
D7EP, MSSQL, ABSDB
BeitragVerfasst: Mo 27.03.06 21:03 
Hi Tim,

user profile iconRamon trifft den Nagel auf den Kopf :zustimm: