Here is my code. I am working on MS SQL SERVER 2008 R2
The problem is that the
is throwing an error of 'Invalid ObjectName #JAM_TMP_TBL_01' despite the fact that it has been successfully created above. Does anyone understand what could be causing this and how I can remedy it? This is the first time that I have seen this and I am not even sure how to research it.
Thanks in advance,
Donald
Code:
IF OBJECT_ID('tempdb..#JAM_TMP_TBL_00','U') is not null
BEGIN
DROP TABLE #JAM_TMP_TBL_00
END;
IF OBJECT_ID('tempdb..#JAM_TMP_TBL_01','U') is not null
BEGIN
DROP TABLE #JAM_TMP_TBL_01
END;
IF OBJECT_ID('tempdb..#JAM_TMP_TBL_02','U') is not null
BEGIN
DROP TABLE #JAM_TMP_TBL_02
END;
IF OBJECT_ID('tempdb..#JAM_TMP_TBL_03','U') is not null
BEGIN
DROP TABLE #JAM_TMP_TBL_03
END;
SELECT DISTINCT T1.ItemCode,T1.Dscription,T3.SlpName,T1.U_BatchNo,T1.U_BatchNotes,
T1.U_Pkging,T1.Price as [Cost],T2.WhsName,
'OnPO' = CASE WHEN T0.DocStatus = 'O' AND T1.LineStatus = 'O'
THEN ROUND(T1.OpenQty,0)
ELSE 0 END,T1.U_Izod,T1.U_Density,T1.U_Meltflow,T1.U_BatchNotes as POBtchNotes,T0.DocDate
INTO #JAM_TMP_TBL_00
FROM OPOR T0 INNER JOIN POR1 T1 ON T0.DocEntry = T1.DocEntry
INNER JOIN OWHS T2 ON T1.WhsCode = T2.WhsCode
INNER JOIN OSLP T3 ON T0.SlpCode = T3.SlpCode
SELECT DISTINCT T1.ItemCode,T1.Dscription,T3.SlpName,T1.U_BatchNo,T1.U_BatchNotes,
T1.U_Pkging,T1.Price as [Cost],T2.WhsName,ROUND(T1.Quantity,0) as Quantity,
T1.U_Izod,T1.U_Density,T1.U_Meltflow,T1.U_BatchNotes as APINVBtchNotes
INTO #JAM_TMP_TBL_01
FROM OPCH T0 INNER JOIN PCH1 T1 ON T0.DocEntry = T1.DocEntry AND T0.U_POCosttype = 'Inventory'
INNER JOIN OWHS T2 ON T1.WhsCode = T2.WhsCode
INNER JOIN OSLP T3 ON T0.SlpCode = T3.SlpCode
WHERE T1.U_BatchNo is not null AND T1.ItemCode not in ('FREIG-H-T','GRIND-I-NG','TOLL-I-NG')
SELECT DISTINCT T1.U_BatchNo,T1.Price
INTO #JAM_TMP_TBL_02
FROM OPCH T0 INNER JOIN PCH1 T1 ON T0.DocEntry = T1.DocEntry
WHERE T0.DocType = 'S' AND T0.U_POCosttype = 'Freight In' AND T1.U_BatchNo is not null
SELECT * FROM #JAM_TMP_TBL_01
The problem is that the
Code:
SELECT * FROM #JAM_TMP_TBL_01
Thanks in advance,
Donald