-- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__getDatevExports] @tgtdate date ,@mode varchar(1) = 'm' ,@files bit ,@authuser varchar(100) AS BEGIN SET NOCOUNT ON; IF [dbo].[fis_getModuleAuth]('fds_reports', @authuser) < 2 THROW 60000, N'not authorized', 1; DECLARE @startdate date, @enddate date; SET @mode = LOWER(@mode); If @mode = 'm' BEGIN SELECT @startdate = [dbo].[date_monthfirst](@tgtdate) ,@enddate = [dbo].[date_monthend](@tgtdate); END ELSE If @mode = 'w' BEGIN SELECT @startdate = [dbo].[date_weekfirst](@tgtdate) ,@enddate = [dbo].[date_weekend](@tgtdate); END DECLARE @contraaccounts as table([account] varchar(10), [name] varchar(100), [vat] numeric(5,2)); insert into @contraaccounts SELECT [account] = [key], [name] = [value], [vat] = TRY_PARSE([value2] as numeric(5,2) USING 'en-US') FROM [dbo].[fds__admin_settings] WHERE [type] = 'contra_account' SELECT [startdate] = @startdate, [enddate] = @enddate, [mode] = @mode , [beraternummer] = 11653 , [mandantennummer] = 62321 , [WJ-Beginn] = DATEFROMPARTS(YEAR(@tgtDate), 1, 1) , [Sachkontenlänge] = ISNULL((SELECT MAX(LEN([account])) FROM @contraaccounts), 4) ; DECLARE @inv TABLE([Id] varchar(20), [InvoiceID] varchar(255), [DocumentName] nvarchar(255), [DateOfCreation] date, [fds] bit, [file_guid] varchar(36)); INSERT INTO @inv SELECT [Id],[invoiceid],[DocumentName],[DateOfCreation] = [DateCreated],[fds] = IIF([isExternal] = 0,1,0), [file_guid] FROM [dbo].[fds__invoices] where CAST([DateCreated] as date) between @startdate AND @enddate and [isfinal] = 1; SELECT inv.[Id],inv.[InvoiceID],inv.[DocumentName],inv.[fds] , [file] = CASE WHEN @files = 1 then finv.[file] ELSE NULL END , inv.[file_guid], [DateOfCreation] --,[order] = ROW_NUMBER() OVER (ORDER BY [DateOfCreation] ASC) FROM @inv as inv LEFT JOIN [dbo].[fds__invoices] as finv on inv.[id] = finv.[id]; DECLARE @SReq TABLE ([id] bigint, [DateOfCreation] datetime, [name] nvarchar(255), [invoice.Id] varchar(15), [customer.ExternalId] bigint, [customer.Id] bigint, [ExternalId] nvarchar(255)); INSERT INTO @SReq SELECT s.[Id], s.[DateOfCreation], s.[name], [invoice.Id] = i.[Id], [customer.ExternalId] = cy.ExternalId , [customer.Id] = cy.[id], s.[ExternalId] FROM [dbo].[fds__invoice_servicerequests] as irq JOIN @inv as i on irq.[InvId] = i.[Id] LEFT JOIN [dbo].[mfr__servicerequests] as s ON irq.[mfr__servicerequest] = s.[id] LEFT JOIN [dbo].[mfr__companies] as cy on s.[CustomerId] = cy.id; With sc as( SELECT s.[invoice.Id], [#] = COUNT(s.[id]) FROM @SReq as s GROUP BY s.[invoice.Id] ), inv as( select iv.[Id] ,[InvoiceId] = iv.[InvoiceId] ,[requestcount] = sc.[#] ,[request] = (SELECT TOP(1) s.[ExternalId] FROM @SReq as s WHERE s.[invoice.Id] = iv.id) ,[balance] = ABS([invoiceBalance]) ,[deb_cred] = CASE WHEN [invoiceBalance] >= 0 THEN 'S' ELSE 'H' END ,[customer] = (SELECT TOP(1) [ExternalId] FROM [dbo].[mfr__companies] as c WHERE c.[Id] = iv.[CustomerId]) ,[contra_account] = ca.[account] ,[Belegdatum] = iv.[DateCreated] ,[Buchungstext] = (SELECT TOP(1) SReq.[name] FROM @SReq as sreq WHERE iv.[Id] = sreq.[invoice.Id]) ,[DateOfCreation] = iv.[DateCreated] ,[file_guid] from [dbo].[fds__invoices] as iv LEFT JOIN [dbo].[fds__invoice_details] as d on iv.[Id] = d.[InvId] LEFT JOIN sc on iv.[id] = sc.[invoice.Id] LEFT JOIN @contraaccounts as ca ON (CASE WHEN d.InvoiceOptions like '%§13b%' and RIGHT(ca.[name], 3) = '13b' then 1 WHEN d.InvoiceOptions like '%§13b%' THEN 0 when ISNULL(iv.[InvoiceVAT_1], 19.0) = ca.[vat] THEN 1 ELSE 0 END) = 1 where iv.Id in (SELECT [Id] FROM @inv) ) select [Umsatz (ohne Soll/Haben-Kz)] = ABS([balance])--CAST(FORMAT(ABS([balance]), '0.00', 'de') as varchar(13)) ,[Soll/Haben-Kennzeichen] = [dbo].[ott_quote_255](UPPER([deb_cred])) ,[WKZ Umsatz] = [dbo].[ott_quote_255]('') ,[Kurs] = NULL ,[Basis-Umsatz] = NULL ,[WKZ Basis-Umsatz] = [dbo].[ott_quote_255]('') ,[Konto] = CAST(iv.[customer] as bigint) --CAST(iv.[customer] as varchar(9)) --(SELECT TOP(1) [customer.ExternalId] FROM @SReq as sreq WHERE iv.[Id] = sreq.[invoice.Id] ORDER BY SReq.DateOfCreation ASC) ,[Gegenkonto (ohne BU-Schlüssel)] = CAST([contra_account] as bigint )--CAST([contra_account] as varchar(9))] ,[BU-Schlüssel] = [dbo].[ott_quote_255]('') ,[Belegdatum] = FORMAT(iv.[Belegdatum], 'ddMM') ,[Belegfeld 1] = [dbo].[ott_quote_255](iv.[InvoiceId]) ,[Belegfeld 2] = [dbo].[ott_quote_255]([dbo].[strings_removeLeading0_255](FORMAT(iv.[Belegdatum], 'ddMMyy'))) ,[Skonto] = [dbo].[ott_quote_255]('') ,[Buchungstext] = [dbo].[ott_quote_255](CAST(ISNULL(LEFT( TRIM(CAST((SELECT TOP(1) SReq.[name] FROM @SReq as sreq WHERE iv.[Id] = sreq.[invoice.Id]) as varchar(255)) ), 60) ,'') as varchar(60))) ,[Postensperre] = NULL ,[Diverse Adressnummer] = [dbo].[ott_quote_255]('') ,[Geschäftspartnerbank] = null ,[Sachverhalt] = null ,[Zinssperre] = null ,[Beleglink] = [dbo].[ott_quote_255](CASE WHEN [file_guid] is null THEN NULL ELSE CAST( 'BEDI "' + LOWER(CAST([file_guid] as varchar(36))) + '"' as varchar(50)) end) --,[order] = ROW_NUMBER() OVER (ORDER BY iv.[DateOfCreation] ASC)] ,[Beleginfo - Art 1] = [dbo].[ott_quote_255]('') ,[Beleginfo - Inhalt 1] = [dbo].[ott_quote_255]('') ,[Beleginfo - Art 2] = [dbo].[ott_quote_255]('') ,[Beleginfo - Inhalt 2] = [dbo].[ott_quote_255]('') ,[Beleginfo - Art 3] = [dbo].[ott_quote_255]('') ,[Beleginfo - Inhalt 3] = [dbo].[ott_quote_255]('') ,[Beleginfo - Art 4] = [dbo].[ott_quote_255]('') ,[Beleginfo - Inhalt 4] = [dbo].[ott_quote_255]('') ,[Beleginfo - Art 5] = [dbo].[ott_quote_255]('') ,[Beleginfo - Inhalt 5] = [dbo].[ott_quote_255]('') ,[Beleginfo - Art 6] = [dbo].[ott_quote_255]('') ,[Beleginfo - Inhalt 6] = [dbo].[ott_quote_255]('') ,[Beleginfo - Art 7] = [dbo].[ott_quote_255]('') ,[Beleginfo - Inhalt 7] = [dbo].[ott_quote_255]('') ,[Beleginfo - Art 8] = [dbo].[ott_quote_255]('') ,[Beleginfo - Inhalt 8] = [dbo].[ott_quote_255]('') ,[KOST1 - Kostenstelle] = [dbo].[ott_quote_255]('') ,[KOST2 - Kostenstelle] = [dbo].[ott_quote_255]('') ,[Kost-Menge] = null ,[EU-Land u. UStID (Bestimmung)] = [dbo].[ott_quote_255]('') ,[EU-Steuersatz (Bestimmung)] = null ,[Abw. Versteuerungsart] = [dbo].[ott_quote_255]('') ,[Sachverhalt L+L] = null ,[Funktionsergänzung L+L] = null ,[BU 49 Hauptfunktionstyp] = null ,[BU 49 Hauptfunktionsnummer] = null ,[BU 49 Funktionsergänzung] = null ,[Zusatzinformation - Art 1] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 1] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 2] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 2] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 3] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 3] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 4] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 4] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 5] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 5] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 6] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 6] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 7] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 7] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 8] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 8] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 9] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 9] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 10] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 10] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 11] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 11] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 12] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 12] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 13] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 13] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 14] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 14] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 15] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 15] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 16] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 16] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 17] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 17] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 18] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 18] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 19] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 19] = [dbo].[ott_quote_255]('') ,[Zusatzinformation - Art 20] = [dbo].[ott_quote_255]('') ,[Zusatzinformation- Inhalt 20] = [dbo].[ott_quote_255]('') ,[Stück] = null ,[Gewicht] = null ,[Zahlweise] = null ,[Forderungsart] = [dbo].[ott_quote_255]('') ,[Veranlagungsjahr] = null ,[Zugeordnete Fälligkeit] = null ,[Skontotyp] = null ,[Auftragsnummer] = [dbo].[ott_quote_255]('') ,[Buchungstyp] = [dbo].[ott_quote_255]('') ,[USt-Schlüssel (Anzahlungen)] = null ,[EU-Land (Anzahlungen)] = [dbo].[ott_quote_255]('') ,[Sachverhalt L+L (Anzahlungen)] = null ,[EU-Steuersatz (Anzahlungen)] = null ,[Erlöskonto (Anzahlungen)] = null ,[Herkunft-Kz] = [dbo].[ott_quote_255]('') ,[Buchungs GUID] = [dbo].[ott_quote_255]('') ,[KOST-Datum] = null ,[Mandatsreferenz] = [dbo].[ott_quote_255]('') ,[Skontosperre] = null ,[Gesellschaftername] = [dbo].[ott_quote_255]('') ,[Beteiligtennummer] = null ,[Identifikationsnummer] = [dbo].[ott_quote_255]('') ,[Zeichnernummer] = [dbo].[ott_quote_255]('') ,[Postensperre bis] = null ,[Bezeichnung SoBil-Sachverhalt] = [dbo].[ott_quote_255]('') ,[Kennzeichen SoBil-Buchung] = [dbo].[ott_quote_255]('') ,[Festschreibung] = 1 ,[Leistungsdatum] = null ,[Datum Zuord. Steuerperiode] = null ,[Fälligkeit] = null ,[Generalumkehr (GU)] = 0 ,[Steuersatz] = null ,[Land] = null --,[Abrechnungsreferenz] --,[BVV-Position] --,[EU-Land u. UStID (Ursprung)] --,[EU-Steuersatz (Ursprung)] from inv as iv order by TRY_CONVERT(integer, SUBSTRING(iv.[InvoiceId], 2,4)), TRY_CONVERT(integer, RIGHT(iv.[InvoiceId], 4)), iv.[DateOfCreation] ASC; WIth debs as ( SELECT ROW_NUMBER() OVER (PARTITION BY [customer.Id] ORDER BY SReq.DateOfCreation ASC) as [#] , [customer.ExternalId] , [customer.Id] FROM @SReq as sreq ), dd as ( SELECT distinct cy.* FROM [mfr__companies] as cy WHERE EXISTS ( SELECT * FROM debs WHERE debs.[customer.Id] = cy.[id] AND debs.[#] = 1) ), cc as ( SELECT ROW_NUMBER() OVER (PARTITION BY dd.[id] ORDER BY CASE WHEN dd.[MainContactId] = c.[id] THEN 0 ELSE 1 END) as '#' , c.* , [company_id] = dd.[id] , [company_name] = dd.[Name] , [isCompany] = CAST ( CASE WHEN ( not dd.[name] like '%c[/]o %' AND ( dd.[Name] like '%mbH%' OR dd.[Name] like '%Ltd%' OR dd.[Name] like '% gbr%' OR dd.[Name] like 'gbr %' OR dd.[Name] like '% OHG%' OR (REPLACE(dd.[Name], '|' , ' ') + ' ') like '% AG %' OR (REPLACE(dd.[Name], '|' , ' ') + ' ') like '% KG %' OR (REPLACE(dd.[Name], '|' , ' ') + ' ') like '% SA %' OR (REPLACE(dd.[Name], '|' , ' ') + ' ') like '% UG %' OR dd.[Name] like '% eV%' or dd.[Name] like '%e[.]V[.]%' OR dd.[Name] like '%Gesellschaft%' OR dd.[Name] like '%Gemeinde%' OR dd.[Name] like '%Verwaltung%' OR dd.[Name] like '%Stadtwerke%' OR dd.[Name] like '%tagesstätte%' OR dd.[Name] like '%schützenverein%' OR dd.[Name] like '%akademie%' OR dd.[Name] like '%universität%' OR dd.[Name] like '%schule%' OR dd.[Name] like '%spedition%' OR dd.[Name] like '%immobilien%' OR dd.[Name] like '%krankenkasse%' OR dd.[Name] like '% holding %' OR dd.[Name] like '% Bautenschutz %' OR dd.[Name] like '%dienstleistung%' OR dd.[Name] like '%weinlokal%' OR dd.[Name] like '%restaurant%' OR dd.[Name] like '% hotel%' OR dd.[Name] like '%kanzlei%' OR dd.[Name] like '%praxis%' OR dd.[Name] like '%großhandel%' OR dd.[Name] like '%tischlerei%' OR dd.[Name] like '%haustechnik%' OR dd.[Name] like '%holztechnik%' OR dd.[Name] like '%heizungsbau%' OR dd.[Name] like '%bautenschutz%' OR dd.[Name] like '%tischlerei%' OR dd.[Name] like '%architekt%' OR dd.[Name] like '%sanitär%' OR dd.[Name] like '%pafümerie%' OR dd.[Name] like '%bauamt%' OR dd.[Name] like '%gebäudereinigung%' OR dd.[Name] like '%handwerksmeister%' OR dd.[Name] like '%fachbetrieb%' OR dd.[Name] like '%ausbau und montagen%' OR dd.[Name] like '%verband %' OR dd.[Name] like '%vermietung%' OR dd.[Name] like '%Bad [&] Heizung%' OR dd.[Name] like '%Bad[&]Wärme%' OR dd.[Name] like '% Düsseldorf%' OR dd.[Name] like '%niederlassung%' OR dd.[Name] like 'zentrum für %' OR dd.[Name] like '% Generalvertretung %' )) THEN 1 ELSE 0 END as bit) FROM [dbo].[mfr__contacts] as c JOIN dd on c.[CompanyId] = dd.[Id] OR dd.[MainContactId] = c.[id] ) SELECT [Konto] = CAST(dd.[ExternalId] as bigint) --CAST(dd.[ExternalId] as varchar(9)) ,[Name (Adressatentyp Unternehmen)] = [dbo].[ott_quote_255](CAST(LEFT(CAST(CASE WHEN cc.[isCompany] = 0 THEN '' ELSE REPLACE(REPLACE(REPLACE(ISNULL( cc.[company_name] ,''), CHAR(13), ' '), CHAR(10), ' '), ' ', ' ') END as varchar(255)), 50) as varchar(50))) ,[Unternehmensgegenstand] = [dbo].[ott_quote_255]('') ,[Name (Adressattyp natürl. Person)] = [dbo].[ott_quote_255](CAST(LEFT(CAST(CASE WHEN cc.[isCompany] = 1 THEN '' ELSE REPLACE(REPLACE(REPLACE(ISNULL( cc.[LastName] ,''), CHAR(13), ' '), CHAR(10), ' '), ' ', ' ') END as varchar(255)), 30) as varchar(30))) ,[Vorname (Adressattyp natürl. Person)] = [dbo].[ott_quote_255](CAST(LEFT(CAST(CASE WHEN cc.[isCompany] = 1 THEN '' ELSE REPLACE(REPLACE(REPLACE(ISNULL( cc.[FirstName] ,''), CHAR(13), ' '), CHAR(10), ' '), ' ', ' ') END as varchar(255)), 30) as varchar(30))) ,[Name (Adressattyp keine Angabe)] = [dbo].[ott_quote_255]('') ,[Adressattyp] = [dbo].[ott_quote_255](CAST(CASE WHEN cc.[isCompany] = 1 THEN 2 ELSE 1 END as varchar(1))) ,[Kurzbezeichnung] = [dbo].[ott_quote_255]('') ,[EU-Land] = [dbo].[ott_quote_255]('') ,[EU-UStID] = [dbo].[ott_quote_255]('') ,[Anrede] = [dbo].[ott_quote_255]('') --CASE WHEN LOWER(LEFT(cc.[Gender],1)) = 'm' THEN 'Herrn' WHEN LOWER(LEFT(cc.[Gender],1)) = 'w' THEN 'Frau' ELSE '' END ,[Titel/Akad. Grad] = [dbo].[ott_quote_255]('') ,[Adelstitel] = [dbo].[ott_quote_255]('') ,[Namensvorsatz] = [dbo].[ott_quote_255]('') ,[Adressart] = [dbo].[ott_quote_255](CAST( CASE WHEN ISNULL(l.[AddressString],'') like '%postfach%' THEN 'PF' ELSE 'STR' END as varchar(3))) ,[Straße] = [dbo].[ott_quote_255](CAST(LEFT(CAST(CASE WHEN ISNULL(l.[AddressString],'') like '%postfach%' THEN '' ELSE ISNULL(l.[AddressString],'') END as varchar(255)),36) as varchar(36))) ,[Postfach] = [dbo].[ott_quote_255](CAST(LEFT(CAST(CASE WHEN ISNULL(l.[AddressString],'') like '%postfach%' THEN TRIM(SUBSTRING(ISNULL(l.[AddressString],''), PATINDEX('%postfach%', ISNULL(l.[AddressString],'')) + 8 , 12)) ELSE '' END as varchar(255)),36) as varchar(36))) ,[Postleitzahl] = [dbo].[ott_quote_255](CAST(l.[Postal] as varchar(10))) ,[Ort] = [dbo].[ott_quote_255](CAST(l.City as varchar(30))) ,[Land] = [dbo].[ott_quote_255](CAST(REPLACE(UPPER(ISNULL(l.[Country], '')),'KE','') as varchar(2))) ,[Versandzusatz] = [dbo].[ott_quote_255]('') ,[Adresszusatz] = [dbo].[ott_quote_255]('') ,[Abweichende Anrede] = [dbo].[ott_quote_255]('') ,[Abw. Zustellbezeichnung 1] = [dbo].[ott_quote_255]('') ,[Abw. Zustellbezeichnung 2] = [dbo].[ott_quote_255]('') ,[Kennz. Korrespondenzadresse] = Cast(1 as int) ,[Adresse Gültig von] = [dbo].[ott_quote_255]('') ,[Adresse Gültig bis] = [dbo].[ott_quote_255]('') ,[Telefon] = [dbo].[ott_quote_255](CAST(ISNULL(cc.[Telephone], dd.[SupportTelephone]) as varchar(60))) ,[Bemerkung (Telefon)] = [dbo].[ott_quote_255]('') ,[Telefon GL] = [dbo].[ott_quote_255]('') ,[Bemerkung (Telefon GL)] = [dbo].[ott_quote_255]('') ,[E-Mail] = [dbo].[ott_quote_255](CAST( CASE WHEN ISNULL(cc.[Email], dd.[SupportMail]) like '%[@]%' THEN REPLACE(LOWER(ISNULL(cc.[Email], dd.[SupportMail])), ' ', '') ELSE NULL END as varchar(60))) ,[Bemerkung (E-Mail)] = [dbo].[ott_quote_255]('') ,[Internet] = [dbo].[ott_quote_255]('') ,[Bemerkung (Internet)] = [dbo].[ott_quote_255]('') ,[Fax] = [dbo].[ott_quote_255]('') ,[Bemerkung (Fax)] = [dbo].[ott_quote_255]('') ,[Sonstige] = [dbo].[ott_quote_255]('') ,[Bemerkung (Sonstige)] = [dbo].[ott_quote_255]('') ,[Bankleitzahl 1] = [dbo].[ott_quote_255]('') ,[Bankbezeichnung 1] = [dbo].[ott_quote_255]('') ,[Bank-Kontonummer 1] = [dbo].[ott_quote_255]('') ,[Länderkennzeichen 1] = [dbo].[ott_quote_255]('') ,[IBAN-Nr. 1] = [dbo].[ott_quote_255]('') ,[IBAN1 korrekt] = [dbo].[ott_quote_255]('') ,[SWIFT-Code 1] = [dbo].[ott_quote_255]('') ,[Abw. Kontoinhaber 1] = [dbo].[ott_quote_255]('') ,[Kennz. Hauptbankverb. 1] = [dbo].[ott_quote_255]('') ,[Bankverb 1 Gültig von] = null ,[Bankverb 1 Gültig bis] = null ,[Bankleitzahl 2] = [dbo].[ott_quote_255]('') ,[Bankbezeichnung 2] = [dbo].[ott_quote_255]('') ,[Bank-Kontonummer 2] = [dbo].[ott_quote_255]('') ,[Länderkennzeichen 2] = [dbo].[ott_quote_255]('') ,[IBAN-Nr. 2] = [dbo].[ott_quote_255]('') ,[IBAN2 korrekt] = [dbo].[ott_quote_255]('') ,[SWIFT-Code 2] = [dbo].[ott_quote_255]('') ,[Abw. Kontoinhaber 2] = [dbo].[ott_quote_255]('') ,[Kennz. Hauptbankverb. 2] = [dbo].[ott_quote_255]('') ,[Bankverb 2 Gültig von] = null ,[Bankverb 2 Gltig bis] = null ,[Bankleitzahl 3] = [dbo].[ott_quote_255]('') ,[Bankbezeichnung 3] = [dbo].[ott_quote_255]('') ,[Bank-Kontonummer 3] = [dbo].[ott_quote_255]('') ,[Länderkennzeichen 3] = [dbo].[ott_quote_255]('') ,[IBAN-Nr. 3] = [dbo].[ott_quote_255]('') ,[IBAN3 korrekt] = [dbo].[ott_quote_255]('') ,[SWIFT-Code 3] = [dbo].[ott_quote_255]('') ,[Abw. Kontoinhaber 3] = [dbo].[ott_quote_255]('') ,[Kennz. Hauptbankverb. 3] = [dbo].[ott_quote_255]('') ,[Bankverb 3 Gültig von] = null ,[Bankverb 3 Gültig bis] = null ,[Bankleitzahl 4] = [dbo].[ott_quote_255]('') ,[Bankbezeichnung 4] = [dbo].[ott_quote_255]('') ,[Bank-Kontonummer 4] = [dbo].[ott_quote_255]('') ,[Länderkennzeichen 4] = [dbo].[ott_quote_255]('') ,[IBAN-Nr. 4] = [dbo].[ott_quote_255]('') ,[IBAN4 korrekt] = [dbo].[ott_quote_255]('') ,[SWIFT-Code 4] = [dbo].[ott_quote_255]('') ,[Abw. Kontoinhaber 4] = [dbo].[ott_quote_255]('') ,[Kennz. Hauptbankverb. 4] = [dbo].[ott_quote_255]('') ,[Bankverb 4 Gültig von] = null ,[Bankverb 4 Gültig bis] = null ,[Bankleitzahl 5] = [dbo].[ott_quote_255]('') ,[Bankbezeichnung 5] = [dbo].[ott_quote_255]('') ,[Bank-Kontonummer 5] = [dbo].[ott_quote_255]('') ,[Länderkennzeichen 5] = [dbo].[ott_quote_255]('') ,[IBAN-Nr. 5] = [dbo].[ott_quote_255]('') ,[IBAN5 korrekt] = [dbo].[ott_quote_255]('') ,[SWIFT-Code 5] = [dbo].[ott_quote_255]('') ,[Abw. Kontoinhaber 5] = [dbo].[ott_quote_255]('') ,[Kennz. Hauptbankverb. 5] = [dbo].[ott_quote_255]('') ,[Bankverb 5 Gültig von] = null ,[Bankverb 5 Gültig bis] = null ,[Leerfeld] = null ,[Briefanrede] = [dbo].[ott_quote_255]('') ,[Grußformel] = [dbo].[ott_quote_255]('') ,[Kundennummer] = [dbo].[ott_quote_255]('') ,[Steuernummer] = [dbo].[ott_quote_255]('') ,[Sprache] = null ,[Ansprechpartner] = [dbo].[ott_quote_255]('') ,[Vertreter] = [dbo].[ott_quote_255]('') ,[Sachbearbeiter] = [dbo].[ott_quote_255]('') ,[Diverse-Konto] = null ,[Ausgabeziel] = null ,[Währungssteuerung] = [dbo].[ott_quote_255]('') ,[Kreditlimit (Debitor)] = null ,[Zahlungsbedingung] = null ,[Fälligkeit in Tagen (Debitor)] = null ,[Skonto in Prozent (Debitor)] = null ,[Kreditoren-Ziel 1 Tg.] = null ,[Kreditoren-Skonto 1 %] = null ,[Kreditoren-Ziel 2 Tg.] = null ,[Kreditoren-Skonto 2 %] = null ,[Kreditoren-Ziel 3 Brutto Tg.] = null ,[Kreditoren-Ziel 4 Tg.] = null ,[Kreditoren-Skonto 4 %] = null ,[Kreditoren-Ziel 5 Tg.] = null ,[Kreditoren-Skonto 5 %] = null ,[Mahnung] = null ,[Kontoauszug] = null ,[Mahntext 1] = null ,[Mahntext 2] = null ,[Mahntext 3] = null ,[Kontoauszugstext] = null ,[Mahnlimit Betrag] = null ,[Mahnlimit %] = null ,[Zinsberechnung] = null ,[Mahnzinssatz 1] = null ,[Mahnzinssatz 2] = null ,[Mahnzinssatz 3] = null ,[Lastschrift] = [dbo].[ott_quote_255]('') ,[Verfahren] = [dbo].[ott_quote_255]('') ,[Mandantenbank] = null ,[Zahlungsträger] = [dbo].[ott_quote_255]('') ,[Indiv. Feld 1] = [dbo].[ott_quote_255]('') ,[Indiv. Feld 2] = [dbo].[ott_quote_255]('') ,[Indiv. Feld 3] = [dbo].[ott_quote_255]('') ,[Indiv. Feld 4] = [dbo].[ott_quote_255]('') ,[Indiv. Feld 5] = [dbo].[ott_quote_255]('') ,[Indiv. Feld 6] = [dbo].[ott_quote_255]('') ,[Indiv. Feld 7] = [dbo].[ott_quote_255]('') ,[Indiv. Feld 8] = [dbo].[ott_quote_255]('') ,[Indiv. Feld 9] = [dbo].[ott_quote_255]('') ,[Indiv. Feld 10] = [dbo].[ott_quote_255]('') ,[Indiv. Feld 11] = [dbo].[ott_quote_255]('') ,[Indiv. Feld 12] = [dbo].[ott_quote_255]('') ,[Indiv. Feld 13] = [dbo].[ott_quote_255]('') ,[Indiv. Feld 14] = [dbo].[ott_quote_255]('') ,[Indiv. Feld 15] = [dbo].[ott_quote_255]('') ,[Abweichende Anrede (Rechnungsadresse)] = [dbo].[ott_quote_255]('') ,[Adressart (Rechnungsadresse)] = [dbo].[ott_quote_255]('') ,[Straße (Rechnungsadresse)] = [dbo].[ott_quote_255]('') ,[Postfach (Rechnungsadresse)] = [dbo].[ott_quote_255]('') ,[Postleitzahl (Rechnungsadresse)] = [dbo].[ott_quote_255]('') ,[Ort (Rechnungsadresse)] = [dbo].[ott_quote_255]('') ,[Land (Rechnungsadresse)] = [dbo].[ott_quote_255]('') ,[Versandzusatz (Rechnungsadresse)] = [dbo].[ott_quote_255]('') ,[Adresszusatz (Rechnungsadresse)] = [dbo].[ott_quote_255]('') ,[Abw. Zustellbezeichnung 1 (Rechnungsadresse)] = [dbo].[ott_quote_255]('') ,[Abw. Zustellbezeichnung 2 (Rechnungsadresse)] = [dbo].[ott_quote_255]('') ,[Adresse Gültig von (Rechnungsadresse)] = null ,[Adresse Gültig bis (Rechnungsadresse)] = null ,[Bankleitzahl 6] = [dbo].[ott_quote_255]('') ,[Bankbezeichnung 6] = [dbo].[ott_quote_255]('') ,[Bank-Kontonummer 6] = [dbo].[ott_quote_255]('') ,[Länderkennzeichen 6] = [dbo].[ott_quote_255]('') ,[IBAN-Nr. 6] = [dbo].[ott_quote_255]('') ,[IBAN6 korrekt] = [dbo].[ott_quote_255]('') ,[SWIFT-Code 6] = [dbo].[ott_quote_255]('') ,[Abw. Kontoinhaber 6] = [dbo].[ott_quote_255]('') ,[Kennz. Hauptbankverb. 6] = [dbo].[ott_quote_255]('') ,[Bankverb 6 Gültig von] = null ,[Bankverb 6 Gültig bis] = null ,[Bankleitzahl 7] = [dbo].[ott_quote_255]('') ,[Bankbezeichnung 7] = [dbo].[ott_quote_255]('') ,[Bank-Kontonummer 7] = [dbo].[ott_quote_255]('') ,[Länderkennzeichen 7] = [dbo].[ott_quote_255]('') ,[IBAN-Nr. 7] = [dbo].[ott_quote_255]('') ,[IBAN7 korrekt] = [dbo].[ott_quote_255]('') ,[SWIFT-Code 7] = [dbo].[ott_quote_255]('') ,[Abw. Kontoinhaber 7] = [dbo].[ott_quote_255]('') ,[Kennz. Hauptbankverb. 7] = [dbo].[ott_quote_255]('') ,[Bankverb 7 Gültig von] = null ,[Bankverb 7 Gültig bis] = null ,[Bankleitzahl 8] = [dbo].[ott_quote_255]('') ,[Bankbezeichnung 8] = [dbo].[ott_quote_255]('') ,[Bank-Kontonummer 8] = [dbo].[ott_quote_255]('') ,[Länderkennzeichen 8] = [dbo].[ott_quote_255]('') ,[IBAN-Nr. 8] = [dbo].[ott_quote_255]('') ,[IBAN8 korrekt] = [dbo].[ott_quote_255]('') ,[SWIFT-Code 8] = [dbo].[ott_quote_255]('') ,[Abw. Kontoinhaber 8] = [dbo].[ott_quote_255]('') ,[Kennz. Hauptbankverb. 8] = [dbo].[ott_quote_255]('') ,[Bankverb 8 Gültig von] = null ,[Bankverb 8 Gültig bis] = null ,[Bankleitzahl 9] = [dbo].[ott_quote_255]('') ,[Bankbezeichnung 9] = [dbo].[ott_quote_255]('') ,[Bank-Kontonummer 9] = [dbo].[ott_quote_255]('') ,[Länderkennzeichen 9] = [dbo].[ott_quote_255]('') ,[IBAN-Nr. 9] = [dbo].[ott_quote_255]('') ,[IBAN9 korrekt] = [dbo].[ott_quote_255]('') ,[SWIFT-Code 9] = [dbo].[ott_quote_255]('') ,[Abw. Kontoinhaber 9] = [dbo].[ott_quote_255]('') ,[Kennz. Hauptbankverb. 9] = [dbo].[ott_quote_255]('') ,[Bankverb 9 Gültig von] = null ,[Bankverb 9 Gültig bis] = null ,[Bankleitzahl 10] = [dbo].[ott_quote_255]('') ,[Bankbezeichnung 10] = [dbo].[ott_quote_255]('') ,[Bank-Kontonummer 10] = [dbo].[ott_quote_255]('') ,[Länderkennzeichen 10] = [dbo].[ott_quote_255]('') ,[IBAN-Nr. 10] = [dbo].[ott_quote_255]('') ,[IBAN10 korrekt] = [dbo].[ott_quote_255]('') ,[SWIFT-Code 10] = [dbo].[ott_quote_255]('') ,[Abw. Kontoinhaber 10] = [dbo].[ott_quote_255]('') ,[Kennz. Hauptbankverb. 10] = [dbo].[ott_quote_255]('') ,[Bankverb 10 Gültig von] = null ,[Bankverb 10 Gültig bis] = null ,[Nummer Fremdsystem] = [dbo].[ott_quote_255]('') ,[Insolvent] = null ,[Mandatsreferenz 1] = [dbo].[ott_quote_255]('') ,[Mandatsreferenz 2] = [dbo].[ott_quote_255]('') ,[Mandatsreferenz 3] = [dbo].[ott_quote_255]('') ,[Mandatsreferenz 4] = [dbo].[ott_quote_255]('') ,[Mandatsreferenz 5] = [dbo].[ott_quote_255]('') ,[Mandatsreferenz 6] = [dbo].[ott_quote_255]('') ,[Mandatsreferenz 7] = [dbo].[ott_quote_255]('') ,[Mandatsreferenz 8] = [dbo].[ott_quote_255]('') ,[Mandatsreferenz 9] = [dbo].[ott_quote_255]('') ,[Mandatsreferenz 10] = [dbo].[ott_quote_255]('') ,[Verknüpftes OPOS-Konto] = null ,[Mahnsperre bis] = null ,[Lastschriftsperre bis] = null ,[Zahlungssperre bis] = null ,[gebührenberechnung] = null ,[Mahngebühr 1] = null ,[Mahngebühr 2] = null ,[Mahngebühr 3] = null ,[Pauschalenberechnung] = null ,[Verzugspauschale 1] = null ,[Verzugspauschale 2] = null ,[Verzugspauschale 3] = null ,[Alternativer Suchname] = null ,[Status] = null ,[Anschrift manuell geändert (Korrespondenzadresse)] = null ,[Anschrift individuell (Korrespondenzadresse)] = null ,[Anschrift manuell geändert (Rechnungsadresse)] = null ,[Anschrift individuell (Rechnungsadresse)] = null ,[Fristberechnung bei Debitor] = null ,[Mahnfrist 1] = null ,[Mahnfrist 2] = null ,[Mahnfrist 3] = null ,[Letzte Frist] = null FROM dd JOIN cc on cc.[#] = 1 AND cc.[company_id] = dd.[id] LEFT JOIN [dbo].[mfr__#locations] as l ON l.[EntityID] = dd.[id] and l.Property = 'Company:Location' END