Hi,
I have added some code to the end of the standard usp_JIWA_BatchPrint_DefaultFilter to extract specific records if DB_category3 condition is meet. So so good but I now want to sort the #CandidatesTempTable records by DB_Category3.Description and DB_Category5.Description.
These 2 fields represent a Delivery run no, And Delivery Order within the Run.
I am having problems with the joins to #CandidatesTempTable - please can you help me.
Added code below :
SET @SP_AppliesTo_IN_PhysicalID = LTRIM(RTRIM(@SP_AppliesTo_IN_PhysicalID))
SET @SP_AppliesTo_IN_LogicalID = LTRIM(RTRIM(@SP_AppliesTo_IN_LogicalID))
DELETE FROM #CandidatesTempTable
WHERE InvoiceNo NOT IN
(
--Sales Orders Status=0,InvTot>0,Cat2(Dlv run=1)
SELECT
InvoiceNo
FROM SO_Main
INNER JOIN
DB_Main ON SO_Main.DebtorID = DB_Main.DebtorID INNER JOIN
DB_Category3 ON DB_Main.Category3ID = DB_Category3.Category3ID
WHERE (SO_Main.Status = 0) AND (SO_Main.InvoiceTotal > 0) AND (DB_Category3.Description = '1')
)
Select * FROM #CandidatesTempTable INNER JOIN
SO_Main ON InvoiceNo = SO_Main.InvoiceNo INNER JOIN
DB_Main ON SO_Main.DebtorID = DB_Main.DebtorID INNER JOIN
DB_Category3 ON DB_Main.Category3ID = DB_Category3.Category3ID INNER JOIN
DB_Category5 ON DB_Main.Category5ID = DB_Category5.Category5ID
ORDER BY DB_Category3.Description, DB_Category5.Description
SET NOCOUNT OFF
GO


