Tricky BAQ selection

I need to select GLJrnDtl records with the following odd criteria

It must select all the records for a certain date EXECPT those records where all the GLAccount for the ARInvoiceNum are the same.
Here’s an example of the data in the GLJrnDtl table

I want the BAQ to exclude rows for invoice 3456 because all the entries are for the same GL Acct.

I can hide these rows when the report renders by using CountDistinct(), but their values still add up into other aggregates (like SUM() ), which I don’t want.

Any hints on how to do this at the BAQ level?

Use a CTE and filter out the records you don’t want. Then use the results of the CTE to perform the second filter in a second query.

Dumb question de jour … What’s “CTE” stand for?

Does this require Sub-BAQs?

Common Table Expression.

Yes. You can change the query type on the SubQuery Options tab.

:grin:
https://goo.gl/0qCljd

1 Like

What’s this Google thing?
:wink:

Awe man I should have included the “internet explanation” here it goes lol
http://bfy.tw/90IG

Sucks that it adds the “LMGTFY” graphics. it’s SOOOO much better when someone clicks the link thinking it will take them right to the answer.

1 Like

Hey I fixed it! All you need to do is put a space before the link! Now the can be properly tricked!

1 Like

I’m gonna need some hand holding…

How do I even make a simple BAQ that only selects records where all the records of a group of records (my outer group here is ARInvoiceNum) have the same value for one field (the field being GLAccount)?

You might be able to use the Subquery Criteria tab on your count field. I’ve used this to filter against Calculated fields, might work for your case:

If you can use straight SQL and maybe do it via external query, if your current version of Epicor doesn’t allow SQL in BAQ (i.e., we have 905702, i understand there is new capability in E10 with BAQs but don’t know details), would something like this work?

SELECT ARInvoiceNum, JournalNum, JournalLine, PostedDate, COUNT(GLAccount) AS Expr1
FROM GLJrnDtl
WHERE (PostedDate > ‘01/01/2014’)
GROUP BY ARInvoiceNum, JournalNum, JournalLine, PostedDate
Having Count(*) = 1

Any chance you guys have a recursive BOM query using a CTE?

Ther’es a recursive BOM query using CTE in the Epicor help

I looked for it in the docs on EpicWeb but couldn’t find it. I thought they went over it at an Insights as well.

Ther’es a recursive BOM query using CTE in the Epicor help

Just for fun, Google recursion.

Nice. I’ve got the BAQ from E10 help, I just don’t have an E10 system to build it on and need the SQL code. I should of made that clear.

If I fully understand the question then…

You can create an inner subquery that does a group by on ARInvoiceNum and GLAcct. Add a calculated field that provides a row count. COUNT(*)

Create a top level query that joins the table to the inner subquery on ARInvoiceNum and GLAcct. Apply criteria to only select inner subquery rows where rowcount = 1.