-- Test query to fetch document type labels for PL11089
-- document_type in lr_source_document is the ID in lr_dictionary

-- Query 1: Get document types for PL11089
SELECT 
    sd.id AS document_id,
    sd.document_number,
    sd.document_type AS type_id,
    d.label AS type_label,
    d.descr AS type_description,
    sd.page_count,
    sd.issued_by
FROM LRSAdmin.lr_source_document sd
LEFT JOIN LRSAdmin.lr_dictionary d ON d.Id = sd.document_type
WHERE sd.document_number = 'PL11089'
ORDER BY sd.id;

-- Query 2: Verify the lr_dictionary structure
SELECT TOP 10
    Id,
    code,
    label,
    category,
    descr
FROM LRSAdmin.lr_dictionary
WHERE Id IN (111, 103, 127)
ORDER BY Id;

-- Query 3: Get all document type mappings
SELECT 
    Id,
    code,
    label,
    category
FROM LRSAdmin.lr_dictionary
WHERE category = 'document_type'
ORDER BY code;

