#Parameter1:Behandler:DataTable:select name+' '+vorname from privat where behandler=1 AND aktiv=1 order by nrprivat
#Parameter2:Mit Name:Table:Ja;Nein
-SQL-
SELECT        TOP (100) PERCENT dbo.faktura.nrfaktura,dbo.DEBITOR.Faelligam, CAST(dbo.DEBITOR.Betrag AS money) AS Betrag, dbo.Faktura.Datum, dbo.Faktura.Faelligam AS Expr1, CAST(dbo.Faktura.Total AS money) AS Total, 
                         dbo.get_name(dbo.Faktura.Nrpatient) AS Patient, dbo.get_name(dbo.Faktura.Nrdebitor) AS Debitor, dbo.Faktura.Statusdatum, dbo.Faktura.Mahndatum1, dbo.Faktura.Mahnfaelligkeit1, dbo.Faktura.Mahngebuehr1, 
                         dbo.Faktura.Mahndatum2, dbo.Faktura.Mahnfaelligkeit2, dbo.Faktura.Mahngebuehr2, dbo.Faktura.Mahndatum3, dbo.Faktura.Mahnfaelligkeit3, dbo.Faktura.Mahngebuehr3, dbo.Faktura.aktiv,
 dbo.PRIVAT.NAME + ' ' + dbo.PRIVAT.VORNAME AS Behandler
FROM            dbo.DEBITOR INNER JOIN
                         dbo.Faktura ON dbo.DEBITOR.Nrfaktura = dbo.Faktura.Nrfaktura  INNER JOIN
                         dbo.PRIVAT ON dbo.Faktura.Nrbehandler = dbo.PRIVAT.NRPRIVAT

WHERE        (dbo.DEBITOR.Status <> 9) AND (dbo.DEBITOR.Mandant = 1) AND (dbo.DEBITOR.aktiv = 1) AND (dbo.Faktura.aktiv = 1) AND (dbo.Faktura.Status <> 9) AND (dbo.DEBITOR.Faelligam > CONVERT(DATETIME, '2015-05-01 00:00:00', 
                         102)) AND (CAST(dbo.DEBITOR.Betrag AS money) > 0) AND (dbo.Faktura.aktiv = 1) AND (dbo.Faktura.aktiv = 1)
and  (dbo.PRIVAT.NAME + ' ' + dbo.PRIVAT.VORNAME='#Parameter1' or '#Parameter1'='')

ORDER BY dbo.DEBITOR.Faelligam
