SELECT SVDOCUMENTSWI.ID, SVDOCUMENTSWI.CREATEDAT, SMCLIENTINFO.NAME, SMSTORELOCATIONS.NAME, SVDOCUMENTSWI.TOTALSUM, SUBSTR(SVDOCUMENTSWI.BASEDOCTYPEANDID, 4) BASE, DECODE(SVDOCUMENTSWI.DOCSTATE, 0, 'Заблокирован', 1, 'Черновик', 2, 'Принят на складе', 3, 'Принят полностью') DOCSTATE FROM SVDOCUMENTSWI, SMCLIENTINFO, SMSTORELOCATIONS WHERE DOCTYPE IN('WI') AND SVDOCUMENTSWI.CREATEDAT <= to_date('03.05.2007', 'DD.MM.YYYY') AND SVDOCUMENTSWI.DOCSTATE < 3 AND SMCLIENTINFO.ID = SVDOCUMENTSWI.CLIENTINDEX AND SVDOCUMENTSWI.LOCATIONTO = SMSTORELOCATIONS.ID ORDER BY SVDOCUMENTSWI.DOCSTATE