得到这个错误并且面临一点因为别名但我的头只是转过身来,你能帮我解决别名错误检查这个
SELECT B.PARTS_NO, B.Adj_Date, B.COST, B.ADJ_DESC, ADJ_FG_QTY_PREV = SUM(B.ADJ_FG_QTY_PREV), ADJ_COGS_QTY_PREV = SUM(B.ADJ_COGS_QTYPREV) , ADJ_FG_QTY = SUM(B.ADJ_FG_QTY), ADJ_COGS_QTY = SUM(B.ADJ_COGS_QTY)
FROM
(
SELECT
PARTS_NO=a.PARTS_NO,
Adj_Date=Convert(varchar(10),a.PROCESSING_DATETIME,105),
COST=ISNULL((SELECT CASE WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=1 THEN ISNULL(a.ECOST_01,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=2 THEN ISNULL(a.ECOST_02,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=3 THEN ISNULL(a.ECOST_03,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=4 THEN ISNULL(a.ECOST_04,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=5 THEN ISNULL(a.ECOST_05,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=6 THEN ISNULL(a.ECOST_06,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=7 THEN ISNULL(a.ECOST_07,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=8 THEN ISNULL(a.ECOST_08,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=9 THEN ISNULL(a.ECOST_09,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=10 THEN ISNULL(a.ECOST_10,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=11 THEN ISNULL(a.ECOST_11,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=12 THEN ISNULL(a.ECOST_12,0)
ELSE 0
END
FROM TITEMBALANCE a
WHERE a.[YEAR]=YEAR(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))
AND a.PARTS_NO=a.PARTS_NO),0),
ADJ_DESC ='CATS',
ADJ_FG_QTY_PREV=SUM(CASE WHEN Convert(numeric(6,0),Convert(varchar(6),a.PROCESSING_DATETIME,112))<>ISNULL(a.COSTING1,0) THEN (CASE WHEN Left(Ltrim(b.REASON_CODE),1)='1' THEN b.QUANTITY_F Else 0 End) else 0 end),
ADJ_COGS_QTYPREV=SUM(CASE WHEN Convert(numeric(6,0),Convert(varchar(6),a.PROCESSING_DATETIME,112))<>ISNULL(a.COSTING1,0) THEN (CASE WHEN Left(Ltrim(b.REASON_CODE),1)='2' THEN b.QUANTITY_F Else 0 End) else 0 end),
ADJ_FG_QTY=SUM(CASE WHEN Convert(numeric(6,0),Convert(varchar(6),a.PROCESSING_DATETIME,112))=ISNULL(a.COSTING1,0) THEN (CASE WHEN Left(Ltrim(b.REASON_CODE),1)='1' THEN b.QUANTITY_F Else 0 End) else 0 end),
ADJ_COGS_QTY=SUM(CASE WHEN Convert(numeric(6,0),Convert(varchar(6),a.PROCESSING_DATETIME,112))=ISNULL(a.COSTING1,0) THEN (CASE WHEN Left(Ltrim(b.REASON_CODE),1)='2' THEN b.QUANTITY_F Else 0 End) else 0 end)
FROM TPARTADJUSTMENTC a INNER JOIN TPARTADJUSTMENTCL b ON a.CARD_NO=b.CARD_NO AND a.INHOUSE_OUTSIDE=b.INHOUSE_OUTSIDE AND a.PARTS_NO=b.PARTS_NO AND a.PROCESS_CODE=b.PROCESS_CODE AND a.FILLER=b.FILLER AND a.PROCESSING_DATETIME=b.PROCESSING_DATETIME
WHERE ISNULL(a.COSTING1,0)=Convert(numeric(6,0),@Period)
GROUP BY a.PARTS_NO,Convert(varchar(10),a.PROCESSING_DATETIME,105),Left(Ltrim(b.REASON_CODE),1)
UNION ALL
SELECT
PARTS_NO=a.PARTS_NO,
Adj_Date=Convert(varchar(10),a.PROCESSING_DATETIME,105),
COST=ISNULL((SELECT CASE WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=1 THEN ISNULL(a.ECOST_01,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=2 THEN ISNULL(a.ECOST_02,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=3 THEN ISNULL(a.ECOST_03,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=4 THEN ISNULL(a.ECOST_04,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=5 THEN ISNULL(a.ECOST_05,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=6 THEN ISNULL(a.ECOST_06,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=7 THEN ISNULL(a.ECOST_07,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=8 THEN ISNULL(a.ECOST_08,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=9 THEN ISNULL(a.ECOST_09,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=10 THEN ISNULL(a.ECOST_10,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=11 THEN ISNULL(a.ECOST_11,0)
WHEN MONTH(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))=12 THEN ISNULL(a.ECOST_12,0)
ELSE 0
END
FROM TITEMBALANCE a
WHERE a.[YEAR]=YEAR(Convert(Datetime,LTRIM(RTRIM(@Period))+'01',112))
AND a.PARTS_NO=a.PARTS_NO),0),
ADJ_DESC ='IMPULSE',
ADJ_FG_QTYPREV=SUM(CASE WHEN Convert(numeric(6,0),Convert(varchar(6),a.PROCESSING_DATETIME,112))<>ISNULL(a.COSTING1,0) THEN (CASE WHEN Left(Ltrim(b.REASON_CODE),1)='1' THEN b.QUANTITY_F Else 0 End) else 0 end),
ADJ_COGS_QTYPREV=SUM(CASE WHEN Convert(numeric(6,0),Convert(varchar(6),a.PROCESSING_DATETIME,112))<>ISNULL(a.COSTING1,0) THEN (CASE WHEN Left(Ltrim(b.REASON_CODE),1)='2' THEN b.QUANTITY_F Else 0 End) else 0 end),
ADJ_FG_QTY=SUM(CASE WHEN Convert(numeric(6,0),Convert(varchar(6),a.PROCESSING_DATETIME,112))=ISNULL(a.COSTING1,0) THEN (CASE WHEN Left(Ltrim(b.REASON_CODE),1)='1' THEN b.QUANTITY_F Else 0 End) else 0 end),
ADJ_COGS_QTY=SUM(CASE WHEN Convert(numeric(6,0),Convert(varchar(6),a.PROCESSING_DATETIME,112))=ISNULL(a.COSTING1,0) THEN (CASE WHEN Left(Ltrim(b.REASON_CODE),1)='2' THEN b.QUANTITY_F Else 0 End) else 0 end)
FROM TPARTADJUSTMENTI a INNER JOIN TPARTADJUSTMENTIL b ON a.CARD_NO=b.CARD_NO AND a.INHOUSE_OUTSIDE=b.INHOUSE_OUTSIDE AND a.PARTS_NO=b.PARTS_NO AND a.PROCESS_CODE=b.PROCESS_CODE AND a.FILLER=b.FILLER AND a.PROCESSING_DATETIME=b.PROCESSING_DATETIME
WHERE ISNULL(a.COSTING1,0)=Convert(numeric(6,0),@Period)
GROUP BY a.PARTS_NO,Convert(varchar(10),a.PROCESSING_DATETIME,105),Left(Ltrim(b.REASON_CODE),1)
) B GROUP BY B.PARTS_NO, B.Adj_Date, B.COST, B.ADJ_DESC