#Parameter1:Journal:DataTable:select datum FROM besrt ORDER BY eintragnr desc, datum desc 
-SQL-
SELECT        dbo.BESRT.Datum, dbo.BESRT.Betrag, SUBSTRING(dbo.BESRI.Referenz, 8, 10) AS fakturanr, dbo.BESRI.Transaktion, dbo.BESRI.Betrag AS Einzelbetrag, dbo.BESRI.Datumverarbeitung AS Valuta, dbo.BESRI.Taxen_PTT, 
                         dbo.BESRI.Verbucht
into #tmp1
FROM            dbo.BESRT INNER JOIN
                         dbo.BESRI ON dbo.BESRT.Eintragnr = dbo.BESRI.besrtnr
                where dbo.besrt.datum='#Parameter1';
SELECT        dbo.#tmp1.Datum, dbo.#tmp1.Betrag, dbo.#tmp1.fakturanr, dbo.#tmp1.Transaktion, dbo.#tmp1.Einzelbetrag, dbo.#tmp1.Valuta, dbo.#tmp1.Taxen_PTT, dbo.#tmp1.Verbucht, dbo.get_name(dbo.Faktura.Nrpatient) AS Patient, 
                         dbo.get_name(dbo.Faktura.Nrdebitor) AS Debitor
FROM            dbo.#tmp1 INNER JOIN
                         dbo.Faktura ON dbo.#tmp1.fakturanr = dbo.Faktura.Nrfaktura
drop table #tmp1;
