select * from ut_WartungsVertraege
where VertrArt in ('H','U')
  and Beginn <= convert(datetime,'2022-08-31',120)
  and AbgerBis < convert(datetime,'2022-08-31',120)
order by RechnAn, KdNr, Nr, VertrArt

select SUM(EP * Menge), SUM(Summe) from ut_WartungsVertraege
where VertrArt in ('H','U') and Aktiv = 1
  and Beginn <= convert(datetime,'2022-08-31',120)
  and AbgerBis < convert(datetime,'2022-08-31',120)
--order by KdNr, Nr, VertrArt
