• Status: Solved
  • Priority: High
  • Security: Public
  • Views: 32
  • Last Modified:

Need some help with SQL Query and GROUP BY

sql.Format("SELECT A.DebitorenNr, A.Name1 AS Name,A.Ort, SUM(B.Einheitbez14wert)AS Gewicht,\
					  COUNT(B.ABNr) AS Auf\
					  FROM Auftragsbestätigungen AS A, Auftragsbestätigungspositionen AS B\
					  A.FakturiertAktiv=%d AND A.storniertAktiv=%d AND\
			                  B.Einheitbez1wert<>%d AND B.Einheitbez1wert<>%d AND\
                                          B.Einheitbez1wert<>%d AND\
					  GROUP BY A.DebitorenNr ,A.Name1, A.Ort\
					  ORDER BY CAST(A.DebitorenNr AS BIGINT)",0,0,50,97,0);

Open in new window

I am filling my list view with these data:
Holder_Name                 = m_ptrRs->GetCollect("Name");
Holder_Ort                      = m_ptrRs->GetCollect("Ort");
Holder_KundenNr           = m_ptrRs->GetCollect("DebitorenNr");
Holder_Gewicht              = m_ptrRs->GetCollect("Gewicht");
Holder_Auftraege            = m_ptrRs->GetCollect("Auf");
I now what to add a column with the last Order No = ABNr and the newest order date = ABdatum

Open in new window

I am filling a list view with these data. I also would like to list the last (highest) ABNr. No. and the last (newest) order date for
each  Name that were saved in the sql table.

In the table = Auftragsbestätigungen is the order date = ABdatum (datetime)

Please help.
Thank you very much.

Best regards,
Thomas Stockbruegger
Thomas Stockbruegger
1 Solution
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Na, das ist doch leicht ;-).

Just add
max(ABNr) as MaxABNr,\
max(ABDatum) as LetztesDatum,\

Open in new window

as second line.
Thomas StockbrueggerAuthor Commented:
Thank you, that was easy.
Best regards,
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now