Batch Print Filter Sort  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Batch Print Filter Sort

Postby 2can2 » Thu Jul 02, 2015 6:58 pm

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
2can2
Frequent Contributor
Frequent Contributor
 
Posts: 171
Joined: Tue Feb 26, 2008 10:24 am
Topics Solved: 25

Re: Batch Print Filter Sort

Postby Mike.Sheen » Thu Jul 02, 2015 11:33 pm

2can2 wrote:now want to sort the #CandidatesTempTable records by DB_Category3.Description and DB_Category5.Description


The following
Code: Select all
ORDER BY DB_Category3.Description, DB_Category5.Description


looks correct... what is the issue - is it not ordering by those fields? Are you getting an error?

Also - please provide the Jiwa version and SQL version this applies to!

Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Batch Print Filter Sort

Postby 2can2 » Fri Jul 03, 2015 8:41 am

Sorry missed those things.
V70115.
The problem is with my link - InvoiceNo. How else can I link the other files need for the sort?

Error it gives is - 'Ambiguous column name - InvoiceNo' - see attached.

Thanks Mike
Attachments

[The extension docx has been deactivated and can no longer be displayed.]

2can2
Frequent Contributor
Frequent Contributor
 
Posts: 171
Joined: Tue Feb 26, 2008 10:24 am
Topics Solved: 25

Re: Batch Print Filter Sort

Postby 2can2 » Fri Jul 03, 2015 11:57 am

Hi,
I have managed to sort this syntax out (with some help -code below for info) by using a 2nd table BUT I have one major problem!!


I think you resort the Records into Invoice number order in the Batch Print app !!

How can I override this!! It is urgent so will also email support on this. Thanks.

Cheers

Select #CandidatesTempTable.* INTO #CandidatesTempTable_Sorted
FROM #CandidatesTempTable INNER JOIN
SO_Main ON #CandidatesTempTable.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
DELETE #CandidatesTempTable

INSERT INTO #CandidatesTempTable
SELECT * FROM #CandidatesTempTable_Sorted
2can2
Frequent Contributor
Frequent Contributor
 
Posts: 171
Joined: Tue Feb 26, 2008 10:24 am
Topics Solved: 25

Re: Batch Print Filter Sort  Topic is solved

Postby Mike.Sheen » Fri Jul 03, 2015 8:41 pm

2can2 wrote:I think you resort the Records into Invoice number order in the Batch Print app !!


I've checked and we don't resort - we call the stored procedure and accept them in the order returned

I think this is your problem:
2can2 wrote:INSERT INTO #CandidatesTempTable
SELECT * FROM #CandidatesTempTable_Sorted


You probably need to ORDER BY on the final result set, otherwise the order returned is unknown and probably not the order they were inserted into - best to be explicit - so something like:

Code: Select all
INSERT INTO #CandidatesTempTable
SELECT *
FROM #CandidatesTempTable_Sorted
ORDER BY #CandidatesTempTable_Sorted.DB_Category3_Description, #CandidatesTempTable_Sorted.DB_Category5_Description


Note - you will need to add the DB_Category3_Description and DB_Category5_Description columns to your #CandidatesTempTable_Sorted table
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: Batch Print Filter Sort

Postby 2can2 » Sat Jul 04, 2015 1:10 pm

Thanks Mike. Got it and it works.
However I did discover that I was trying to sort in the wrong place. I put the sort code at the end of usp_JIWA_SalesOrders_SOBatchPrintGetActions
which I have renamed and pointed in System to it and it works a treat!!
This software is so bloody powerful we just need to understand how to do things - fabulous.

Cheers
2can2
Frequent Contributor
Frequent Contributor
 
Posts: 171
Joined: Tue Feb 26, 2008 10:24 am
Topics Solved: 25


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 4 guests