#Parameter1:Datum von:datetime:firstofcurrentyear
#Parameter2:Datum bis:datetime:currentdate
#Parameter3:Behandler:DataTable:select name+' '+vorname from privat where behandler=1 AND aktiv=1 order by nrprivat
-SQL-
SELECT        dbo.faktura.nrfaktura, dbo.faktura.nrdebitor, dbo.faktura.nrpatient, dbo.faktura.datum, dbo.faktura.total, dbo.faktura.status, dbo.get_name(dbo.faktura.nrpatient) AS Patient, 
                         CASE WHEN nrdebitor <> dbo.faktura.nrpatient THEN dbo.get_name(Nrdebitor) ELSE '' END AS Debitor, dbo.privat.name + ' ' + dbo.privat.vorname AS behandler, dbo.behandlu.mwstsatz, 
                         dbo.RoundToFiveOrZero(dbo.faktura.total / (100.00+DBO.BEHANDLU.MWSTSATZ) * dbo.behandlu.mwstsatz) AS MwSt, dbo.RoundToFiveOrZero(dbo.faktura.total - dbo.faktura.total / (100.00+DBO.BEHANDLU.MWSTSATZ) * dbo.behandlu.mwstsatz) AS Netto, 
                         dbo.RoundToFiveOrZero(dbo.faktura.total / (100.00+DBO.BEHANDLU.MWSTSATZ) * dbo.behandlu.mwstsatz + (dbo.faktura.total - dbo.faktura.total / (100.00+DBO.BEHANDLU.MWSTSATZ) * dbo.behandlu.mwstsatz)) AS BRUTTO
FROM            dbo.faktura INNER JOIN
                         dbo.privat ON dbo.faktura.nrbehandler = dbo.privat.nrprivat INNER JOIN
                         dbo.behandlu ON dbo.faktura.nrbehandlung = dbo.behandlu.nrbehandlung
where  datum>='#Parameter1 00:00:00' and datum <='#Parameter2 23:59:59' and (''='#Parameter3' or '#Parameter3'= dbo.privat.name+' '+dbo.privat.vorname)  