#Parameter1:Journal:DataTable:select eintragnr as keyvalue, convert(varchar(10),datum,104) 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.eintragnr=#Parameter1;
SELECT        #tmp1.Datum, #tmp1.Betrag, #tmp1.fakturanr, #tmp1.Transaktion, #tmp1.Einzelbetrag, #tmp1.Valuta, #tmp1.Taxen_PTT, #tmp1.Verbucht, dbo.get_name(dbo.Faktura.Nrpatient) AS Patient, 
                         dbo.get_name(dbo.Faktura.Nrdebitor) AS Debitor
FROM            #tmp1 INNER JOIN
                         dbo.Faktura ON #tmp1.fakturanr = dbo.Faktura.Nrfaktura;
drop table #tmp1;