I have a BAQ that I am attempting to use to pull attachments links for material picked to jobs.
The working part of the query goes through the part tran table filtered to -MTL transactions and recursively goes through JobNumber = Lot Number, for the sub level parts and displays the results showing the hierarchy and grabs all the lower level lot numbers.
I now want to do a join to the results of that subquery to grab attachments from a bunch of different tables and union those to my original results so I’m left with all the material that has been picked for top to lower level along with any attachments linked to the lot.
As soon as I add an additional union to my baq, if I save or run the query, it crashes epicor.
This works:
This crashes epicor
Crash error:
Which after looking online appears it could have something to do with an infinite recursion loop. Which does not make sense since the recursion portion works without the union.
ok so I got the query loaded I don’t fully understand what you are doing but that’s fine. YOu want to add another Union to this? A union to which table?
I want to take the results of subquery “FullBOM” and join it to the attachment table to find lots that have attachments linked to them and union those results back to the “FullBOM” subquery. Results should look like this
Yep I should’ve specified there’s going to be 5 different areas that documents related to that lot can be attached. RcvHead, RcvDtl, PartLot, JobHead, JobOper . I want to do a union to avoid joining to the attachment rows, which would result in a lot of duplicates
Regarding the crash part - Just glancing at the export in a text editor, @LotNum gets cast a couple of different ways in a union’d query. Looks like it’s probably valid SQL, but casts plus unions can confuse BAQ. Sometimes if you typecast one thing in a union, BAQ will complain until the entire expression of every instance of that field in the stack is cast identically the same way. Like, the entire expression:
-- BAQ will sometimes be unhappy with this kind of pattern
select cast('a' as nvarchar(1))
union all
select case where 1=1 then cast('b' as nvarchar(1)) else cast('c' as nvarchar(1)) end
-- while loving this
select cast('a' as nvarchar(1))
union all
select cast(case where 1=1 then 'b' else 'c' end as nvarchar(1))