SELECT 
    DOCUMENTS.ID, 
    DOCUMENTS.DOCUMENT_BASE_TYPE, 
    DOCUMENTS.DATE_DOCUMENT, 
    DOCUMENTS.MARK, 
    DOCUMENTS.ID_MASTER, 
    DOCUMENTS.ID_USER_CHANGED, 
    DOCUMENTS.ID_USER_DELETED, 
    DOCUMENTS.DATE_CHANGED, 
    DOCUMENTS.DATE_DELETED, 
    DOCUMENTS.DATE_ACTUAL_FROM, 
    DOCUMENTS.DATE_ACTUAL_TO, 
    DOCUMENTS.HISTORY_VERSION, 
    DOCUMENTS.ID_DOCUMENT_TYPES, 
    DOCUMENTS.DESCRIPTION_RTF, 
    DOCUMENTS.DESCRIPTION, 
    DOCUMENTS.INTRODUCTION_TEXT, 
    DOCUMENTS.INTRODUCTION_TEXT_RTF, 
    DOCUMENTS.FINAL_TEXT, 
    DOCUMENTS.FINAL_TEXT_RTF, 
    DOCUMENTS.DELIVERY_TEXT, 
    DOCUMENTS.DELIVERY_TEXT_RTF, 
    DOCUMENTS.SUBJECT, 
    DOCUMENTS.DATE_ADMISSION, 
    DOCUMENTS.DATE_DUE, 
    DOCUMENTS.DATE_CHARGEBILITY_DATE, 
    DOCUMENTS.DATE_RELEASE, 
    DOCUMENTS.DATE_EXP_REALIZATION, 
    DOCUMENTS.DATE_REALIZATION, 
    DOCUMENTS.DATE_DELIVERY_DATE, 
    DOCUMENTS.DATE_RECIVE, 
    DOCUMENTS.TRANSPORT_TYPE, 
    DOCUMENTS.PAYMENT_TYPE, 
    DOCUMENTS.ID_STOCKS_PREDEFINED, 
    DOCUMENTS.ID_CURR, 
    DOCUMENTS.EXCHANGE_RATE, 
    DOCUMENTS.SUM, 
    DOCUMENTS.SUM_LC, 
    DOCUMENTS.SUM_VAT, 
    DOCUMENTS.SUM_VAT_LC, 
    DOCUMENTS.VAT, 
    DOCUMENTS.VAT_LC, 
    DOCUMENTS.FIXED_EXCHANGE_RATE, 
    DOCUMENTS.ID_TRANSFER_STOCK, 
    DOCUMENTS.ID_TRANSFER_PAIR, 
    DOCUMENTS.ID_NS, 
    DOCUMENTS.NS_CODE, 
    DOCUMENTS.NS_EVID_CODE, 
    DOCUMENTS.NS_NUMBER, 
    DOCUMENTS.PROFIT_LOCKING_FLAGS, 
    DOCUMENTS.PROFIT_VALUE, 
    DOCUMENTS.PROFIT_PERCENT, 
    DOCUMENTS.DISCOUNT_PERCENT, 
    DOCUMENTS.DISCOUNT_VALUE, 
    DOCUMENTS.ACCOUNT_NUMBER, 
    DOCUMENTS.VARIABLE_SYMBOL, 
    DOCUMENTS.SPECIFIC_SYMBOL, 
    DOCUMENTS.ID_LINKED_DOCUMENT, 
    DOCUMENTS.BANK_CODE, 
    DOCUMENTS.CONSTANT_SYMBOL, 
    DOCUMENTS.DRAFT, 
    DOCUMENTS.EXTERNAL_NUMBER, 
    DOCUMENTS.PAYMENT_STATUS, 
    DOCUMENTS.PAYMENT_STATUS_LC, 
    DOCUMENTS.ID_BA_REGISTER, 
    DOCUMENTS.DATE_EXPECTED_PAYMENT, 
    DOCUMENTS.ID_DOCUMENT_TYPES_BC, 
    DOCUMENTS.ID_LINKED_DOCUMENT_SOURCE, 
    DOCUMENTS.ID_USER, 
    DOCUMENTS.GUID, 
    DOCUMENTS.IBAN, 
    DOCUMENTS.SWIFT, 
    DOCUMENTS.ECR_FLAG, 
    DOCUMENTS.TOTAL_PRICE_CALCULATION, 
    DOCUMENTS.IST_ENABLED, 
    DOCUMENTS.IST_CHARGEABILITY_DATE, 
    DOCUMENTS.ID_IST_COMMERCE_TYPE, 
    DOCUMENTS.ID_IST_GEO_REGION, 
    DOCUMENTS.ID_IST_TRANSPORT_TYPES, 
    DOCUMENTS.IST_EXCHANGE_RATE, 
    DOCUMENTS.ID_IST_DELIVERY_TERMS, 
    DOCUMENTS.ID_IST_STATES, 
    DOCUMENTS.IS_LOCKED, 
    DOCUMENTS.DATE_USER_CHANGE, 
    DOCUMENTS.LINKED_DOCUMENT_NS_NUMBER, 
    DOCUMENTS.ID_AUTO_SOURCE_DOCUMENT, 
    DOCUMENTS.ERROR_TYPE, 
    DOCUMENTS.PARTNER_REG, 
    DOCUMENTS.PARTNER_TAX, 
    DOCUMENTS.PARTNER_VAT_NO_NUM, 
    DOCUMENTS.PARTNER_VAT_NO_STATE, 
    DOCUMENTS.PARTNER_CENTER, 
    DOCUMENTS.PARTNER_DEPARTMENT, 
    DOCUMENTS.PARTNER_STREET, 
    DOCUMENTS.PARTNER_STREET_NO, 
    DOCUMENTS.PARTNER_POSTCODE, 
    DOCUMENTS.PARTNER_CITY, 
    DOCUMENTS.PARTNER_ID_CITIES, 
    DOCUMENTS.PARTNER_STATE, 
    DOCUMENTS.PARTNER_ID_STATES, 
    DOCUMENTS.PARTNER_PA_STREET, 
    DOCUMENTS.PARTNER_PA_STREET_NO, 
    DOCUMENTS.PARTNER_PA_POSTCODE, 
    DOCUMENTS.PARTNER_PA_CITY, 
    DOCUMENTS.PARTNER_PA_ID_CITIES, 
    DOCUMENTS.PARTNER_PA_STATE, 
    DOCUMENTS.PARTNER_PA_ID_STATES, 
    DOCUMENTS.PARTNER_DA_STREET, 
    DOCUMENTS.PARTNER_DA_STREET_NO, 
    DOCUMENTS.PARTNER_DA_POSTCODE, 
    DOCUMENTS.PARTNER_DA_CITY, 
    DOCUMENTS.PARTNER_DA_ID_CITIES, 
    DOCUMENTS.PARTNER_DA_STATE, 
    DOCUMENTS.PARTNER_DA_ID_STATES, 
    DOCUMENTS.PARTNER_NAME, 
    DOCUMENTS.ID_PARTNER, 
    DOCUMENTS.PARTNER_PA_NAME, 
    DOCUMENTS.PARTNER_DA_NAME, 
    DOCUMENTS.PARTNER_PA_DIFF, 
    DOCUMENTS.PARTNER_DA_DIFF, 
    DOCUMENTS.LINKED_COMMISIONS, 
    DOCUMENTS.GUID_OMEGA, 
    DOCUMENTS.PARTNER_CONTACT_ID, 
    DOCUMENTS.DATE_VALIDITY, 
    DOCUMENTS.OMEGA_FIRM_ID, 
    DOCUMENTS.IS_VAT_BY_PAYMENT, 
    DOCUMENTS.EXPECTED_PAYMENT_DATE_LOCK, 
    DOCUMENTS.ORIGIN_NUMBER, 
    DOCUMENTS.ADDITIONAL_COSTS_LC, 
    DOCUMENTS.DATE_RESERVATION, 
    DOCUMENTS.GUID_EXT, 
    DOCUMENTS.ID_SOURCE_DOCUMENT, 
    DOCUMENTS.PV_ACCEPT_COMPOSITES, 
    DOCUMENTS.DATE_LAST_PAYMENT, 
    DOCUMENTS.WEIGHT_STOCK_ITEMS, 
    DOCUMENTS.DOCUMENTATION_AVAL, 
    DOCUMENTS.ID_DEVICE, 
    DOCUMENTS.REPEATABLE_DOC_CREATE, 
    DOCUMENTS.MONTHS_TO_REPEAT, 
    DOCUMENTS.TYPE_MOVE_DATE_REPEAT, 
    DOCUMENTS.ECR_UID, 
    DOCUMENTS.ECR_OKP, 
    DOCUMENTS.ECR_ORIGINAL_DOCUMENT, 
    DOCUMENTS.ECR_REPAIR, 
    DOCUMENTS.ECR_RETURN, 
    DOCUMENTS.ECR_INVALID_DOCUMENT, 
    DOCUMENTS.ECR_PARAGON, 
    DOCUMENTS.ECR_PARAGON_NUMBER, 
    DOCUMENTS.ECR_PARAGON_DATE_TIME, 
    DOCUMENTS.IS_FROM_STOCKTAKING, 
    DOCUMENTS.ECR_CASH_PAY, 
    DOCUMENTS.ECR_CARD_PAY, 
    DOCUMENTS.ECR_CHEQUE_PAY, 
    DOCUMENTS.ECR_DISABLE_PRINT, 
    DOCUMENTS.IST_PARTNER_VAT_NO_NUM, 
    DOCUMENTS.TAX_TRANSFER_LIABILITY, 
    DOCUMENTS.ID_SENT_NOTIFICATION, 
    DOCUMENTS.DATE_SENT_NOTIFICATION, 
    DOCUMENTS.DATE_VATRATE
FROM
     DOCUMENTS
    INNER JOIN DOCUMENT_CUSTOM_COLUMNS ON (DOCUMENTS.ID = DOCUMENT_CUSTOM_COLUMNS.ID_DOCUMENT)
WHERE
    (DOCUMENTS.HISTORY_VERSION = 1) AND (DOCUMENTS.DOCUMENT_BASE_TYPE = 1794)


