---
description: >-
  This is the script, which is responsible for collection all the address data,
  which needs to be exported.
---

# Datev Export sqlMainData Example

### Available Parameters

1. @company - If you work with multiple companies, you have to export each company by it's own.
2. @dateFrom - Start date for the export
3. @dateUntil - End date for the export

### Example Usages

```sql
 SELECT adr.id AS Kundennummer,
       CASE WHEN adrIsCustomer = 1 THEN adr.adrDebitor ELSE adr.adrKreditor END AS Konto,
       adr.adrName AS Firmenname,
       adr.adrLastName as Nachname,
       adr.adrFirstName as Vorname,
       '' AS Anrede,
       'STR' AS Adresstyp,
       adrLoc.alocStreet AS Strasse,
       adrLoc.alocStreetNumber AS Hausnummer,
       adrLoc.alocZip AS PLZ,
       adrLoc.alocCity AS Stadt,
       adrLoc.alocAdditionalInfo AS Zusatzinformation
  FROM [dbo].[address] AS adr
  LEFT JOIN addressLocation AS adrLoc ON adrLoc.id = adr.adrDefaultInvoiceAddress
  LEFT JOIN country AS country ON country.id = adrLoc.alocCountryId
 WHERE adr.adrIsCustomer = 1 OR adr.adrIsSupplier = 1
```
