跳至主要內容

多查询调用变量

五六零网校小于 1 分钟

代码示例

DECLARE @stardata datetime

DECLARE @enddata datetime

SET @stardata = /* T4.DocDate = */  '[%0]' 

SET @enddata = /* T4.DocDate = */  '[%1]' 

  

SELECT

T0.[ItemCode],

    T0.[ItemName], (

        SELECT SUM(T4.[Quantity]) FROM PDN1 T4 WHERE T4.[ItemCode] = T0.[ItemCode] AND T4.[DocDate] >= @stardata AND T4.[DocDate] <= @enddata

    ) AS '采购收货', (

        SELECT SUM(T5.[Quantity]) FROM RPD1 T5 WHERE T5.[ItemCode] = T0.[ItemCode] AND T5.[DocDate] >= @stardata AND T5.[DocDate] <= @enddata

    ) AS '采购退货', (

        SELECT SUM(T6.[Quantity]) FROM IGE1 T6 WHERE T6.[ItemCode] = T0.[ItemCode] AND T6.[DocDate] >= @stardata AND T6.[DocDate] <= @enddata

    ) AS '库存发货', (

        SELECT SUM(T7.[Quantity]) FROM IGN1 T7 WHERE T7.[ItemCode] = T0.[ItemCode] AND T7.[DocDate] >= @stardata AND T7.[DocDate] <= @enddata

    ) AS '库存收货', (

        SELECT SUM(T8.[Quantity]) FROM PCH1 T8 WHERE T8.[ItemCode] = T0.[ItemCode] AND T8.[DocDate] >= @stardata AND T8.[DocDate] <= @enddata

    ) AS '应付发票'

FROM

OITM T0

GROUP BY

T0.[ItemCode],

    T0.[ItemName]