sql use bo -- Alle 2 wöchentlichen Kunden werden ausgegeben Select b.Bezeichnung, b.BestellId,a.Vorname, a.Nachname, a.Strasse, a.Plz, a.Ort, a.AdressId, t.Tourpos, t.TourNr,k.Wert From dTour t join dBestellung b On t.TourNr = b.TourNr Join Adresse a On a.AdressId = b.AdressId Left Join Kontakt k On a.Adressid = k.Adressid Where t.BestellId = b.BestellId And k.Text = 'Telefon' And datediff(dd,datepart(dw,getdate())-1,getdate()) between b.von and coalesce(b.bis,datediff(dd,datepart(dw,getdate())-1,getdate())) And b.LadenId = 'BIOKORB' And Exists (Select Top 1 c.EAN From dBestellPos c Where c.BestellId = b.BestellId And datediff(dd, c.von, datediff(dd,datepart(dw,getdate())-1,getdate())) >= 0 And ( c.bis is Null Or c.bis = 0 Or datediff(dd, c.bis, datediff(dd,datepart(dw,getdate())-1,getdate())) <= 0) And (datediff(dd, datediff(dd,datepart(dw,getdate())-1,getdate()) , c.von)/7) % c.periode = 0 and c.Periode = 2)