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 StockbrueggerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Qlemo"Batchelor", 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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Thomas StockbrueggerAuthor Commented:
Thank you, that was easy.
Best regards,
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.