Отклонение от покупной цены
В моем конкретном сценарии c (снимок экрана) Отчет показывает Отгрузку (шаг1), а затем Счет-фактуру (шаг2). И я хочу, чтобы вся эта информация была в одном ряду. Мне нужно скрыть строку, когда POP_TYPE = Отгрузка, но как я могу получить значения QTY SHIPPED и PURCHASE PRICE в строке POP_TYPE = INVOICE? Хитрость заключается в том, что значение «Цена покупки» и «Цена счета-фактуры» - это одно и то же поле, которое меняет значение в POP_TYPE, т.е. «Отгрузка» или «Счет-фактура». Любая идея или утверждение, чтобы решить этот сценарий?
Ниже приводится фактический сгенерированный системой код для отчета:
select [ASIEXP28].[receiptdate] AS 'Receipt Date',
[ASIEXP28].[POPRCTNM] AS 'POP Receipt Number',
[ASIEXP28].[BACHNUMB] AS 'Batch Number',
[ASIEXP28].[PONUMBER] AS 'PO Number',
[ASIEXP28].[VNDDOCNM] AS 'Vendor Document Number',
[ASIEXP28].[VENDORID] AS 'Vendor ID',
RA.dbo.DYN_FUNC_POP_Type([ASIEXP28].POPTYPE) AS 'POP Type',
[ASIEXP28].[ITEMNMBR] AS 'Item Number',
[ASIEXP28].[ITEMDESC] AS 'Item Description',
[ASIEXP28].[UOFM] AS 'U Of M',
[ASIV0001].[QTYSHPPD] AS 'QTY Shipped',
[ASIV0001].[QTYINVCD] AS 'QTY Invoiced',
[ASIV0001].[QTYMATCH] AS 'QTY Matched',
[ASIEXP28].[LOCNCODE] AS 'Location Code',
(CASE WHEN [ASIEXP28].[UNITCOST]<0 THEN '-'+(SELECT CASE WHEN (SELECT CYSYMPLC FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')) = 0 THEN RTRIM(CRNCYSYM)+(SELECT CASE WHEN (SELECT INCLSPAC FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')) = 1 THEN ' ' ELSE '' END FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')) ELSE '' END FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR'))+LTRIM(STR(abs([ASIEXP28].[UNITCOST]),100,(SELECT DECPLCUR-1 FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')))) ELSE(SELECT CASE WHEN (SELECT CYSYMPLC FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')) = 0 THEN RTRIM(CRNCYSYM)+(SELECT CASE WHEN (SELECT INCLSPAC FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')) = 1 THEN ' ' ELSE '' END FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')) ELSE '' END FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR'))+LTRIM(STR([ASIEXP28].[UNITCOST],100,(SELECT DECPLCUR-1 FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR'))))+(SELECT CASE WHEN (SELECT CYSYMPLC FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')) <> 0 THEN (SELECT CASE WHEN (SELECT INCLSPAC FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')) = 1 THEN ' ' ELSE '' END FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR'))+RTRIM(CRNCYSYM) ELSE '' END FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')) END) AS 'Unit Cost',
(CASE WHEN [ASIEXP28].[EXTDCOST]<0 THEN '-'+(SELECT CASE WHEN (SELECT CYSYMPLC FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')) = 0 THEN RTRIM(CRNCYSYM)+(SELECT CASE WHEN (SELECT INCLSPAC FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')) = 1 THEN ' ' ELSE '' END FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')) ELSE '' END FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR'))+LTRIM(STR(abs([ASIEXP28].[EXTDCOST]),100,(SELECT DECPLCUR-1 FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')))) ELSE(SELECT CASE WHEN (SELECT CYSYMPLC FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')) = 0 THEN RTRIM(CRNCYSYM)+(SELECT CASE WHEN (SELECT INCLSPAC FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')) = 1 THEN ' ' ELSE '' END FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')) ELSE '' END FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR'))+LTRIM(STR([ASIEXP28].[EXTDCOST],100,(SELECT DECPLCUR-1 FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR'))))+(SELECT CASE WHEN (SELECT CYSYMPLC FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')) <> 0 THEN (SELECT CASE WHEN (SELECT INCLSPAC FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')) = 1 THEN ' ' ELSE '' END FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR'))+RTRIM(CRNCYSYM) ELSE '' END FROM DYNAMICS..MC40200 WHERE CURNCYID = ISNULL(NULLIF([ASIEXP28].[CURNCYID],''),'PKR')) END) AS 'Extended Cost',
[ASIEXP28].[USER2ENT] AS 'User To Enter',
[ASIEXP28].PSTGSTUS AS 'Posting Status',
[ASIEXP28].[PTDUSRID] AS 'Posted User ID' from RA..[ASIEXP28]
left join RA..[ASIV0001] on [ASIEXP28].[POPRCTNM] = [ASIV0001].[POPRCTNM] and
[ASIEXP28].[RCPTLNNM]=[ASIV0001].[RCPTLNNM]
WHERE ([ASIEXP28].[receiptdate] BETWEEN @DFrom AND @DTo) ORDER BY [ASIEXP28].[PONUMBER]