# CTE-based BAQ Report

**URL:** <https://www.epiusers.help/t/cte-based-baq-report/52333>\
**Category:** Epicor ERP 10\
**Tags:** e10\
**Created:** [February 7, 2019, 5:57pm UTC](https://www.epiusers.help/t/cte-based-baq-report/52333 "2019-02-07T17:57:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![BA-Quest](https://www.epiusers.help/user_avatar/www.epiusers.help/ba-quest/32/769_2.png) [@BA-Quest](https://www.epiusers.help/u/BA-Quest)\
**Post date:** [February 7, 2019, 5:57pm UTC](https://www.epiusers.help/t/cte-based-baq-report/52333/1 "2019-02-07T17:57:44Z")

</div>

Might anyone have had previous success with creating a BAQ report using a CTE-based BAQ?

General problem I’m having: The CTE BAQ behaves as expected when entering a part number as a BAQ parameter - but - the BAQ report seems to maintain the parameter option value even when running through the various part assembly levels. In addition, the BAQ report appears to recognize the assembly levels, but the grouping of that data only seems to run one-level higher.

Instead of constructing a top-down BOM-level view, the requirement here is opposite of that – when I enter a part number as the parameter, I need to see if it exists in an upper-level assembly… then see if that assembly exists in another upper-level assembly, and so on. Reason? The Sales Department wants to know all of the sales orders attributed to the original part (_which could be a sub-component of a larger assembly that we sell to customers_).

I’m satisfied with the results of the CTE and have tested it on several part numbers (here’s one simple example):

![2019-02-06_9-12-22](https://epiusers.help/uploads/default/original/2X/7/70320c08a62d7b4450f035bb9493bbe6fd86d510.png)

From above… part #100-821-4223 is a sub-component of #100-821-4200 - but #100-821-4200 is not a member of any other parent assembly. That is expected. Notice that you cannot find #100-821-4200 as a material part in level 1.

I merely used this exact CTE to feed a new BAQ report. I can pull data into the report, but it certainly doesn’t follow the progression of level 0 to level 1 to level 2 that the CTE follows.

I’m guessing it is because of my misunderstanding of grouping on the SSRS report - but - if I construct the report with NO grouping and just pull in the exact 3 fields above in the “Details” row (_so they can simply repeat as displayed records until the recordset is exhausted_), the material part value is repeated through all levels.

Any special considerations for using CTE in a BAQ report? If “grouping” is inherent in the CTE level value, how is this maintained in SSRS grouping? What might your suggestions be for displaying the simple matrix of results illustrated above in an SSRS report?

As always, thanks very much for the help.

**EDIT** : I forgot to add the SSRS report results:

 ![2019-02-07_10-05-50](https://epiusers.help/uploads/default/original/2X/f/f36493c36353503b987016168e2eaa1533661ab9.png)

---

<div class="post-metadata">

**Author:** ![Banderson](https://www.epiusers.help/user_avatar/www.epiusers.help/banderson/32/50875_2.png) [@Banderson](https://www.epiusers.help/u/Banderson)\
**Post date:** [February 7, 2019, 6:26pm UTC](https://www.epiusers.help/t/cte-based-baq-report/52333/2 "2019-02-07T18:26:41Z")

</div>

**Unsolicited opinion** : that seems like the perfect thing for a dashboard… Do you _need_ it on paper? Maybe just tell them it can’t be done on a report? makes your life easier, and then they have up to date information.

It doesn’t solve your problem, but that’s what I would do.

---

<div class="post-metadata">

**Author:** ![BA-Quest](https://www.epiusers.help/user_avatar/www.epiusers.help/ba-quest/32/769_2.png) [@BA-Quest](https://www.epiusers.help/u/BA-Quest)\
**Post date:** [February 7, 2019, 6:39pm UTC](https://www.epiusers.help/t/cte-based-baq-report/52333/3 "2019-02-07T18:39:14Z")

</div>

@Banderson – I’m definitely leaning towards your suggestion at this point. Nah - we don’t really need this solution to be report based. At my company, the default is to provide reporting, rather than dashboards. However, in this case, since we also have to link the part list back to historical sales orders, the dashboard approach would truly be best (_especially to present multi-sourced data in different data grids_).

I’ll wait for a bit to see if there might be additional suggestions on this, but I think I might be reloading the chamber to do exactly what you’re talking about! 🙂

---

<div class="post-metadata">

**Author:** ![hkeric.wci](https://www.epiusers.help/user_avatar/www.epiusers.help/hkeric.wci/32/52019_2.png) [@hkeric.wci](https://www.epiusers.help/u/hkeric.wci)\
**Post date:** [February 7, 2019, 6:47pm UTC](https://www.epiusers.help/t/cte-based-baq-report/52333/4 "2019-02-07T18:47:21Z")

</div>

The way I did my CTE is I always maintained the Top-Level Columns, Showed an Hierarchy for Sorting…

- Top Level Job
- Demand
- Job Number

 ![2019-02-07_1344](https://www.epiusers.help/uploads/default/original/2X/d/d7bb4ab55822499ced0c601a1348a6be33a8543a.png)

This is where I started… First made a SQL Prototype for me this was related to JobProd (Job Demands) [https://www.essentialsql.com/recursive-ctes-explained/](https://www.essentialsql.com/recursive-ctes-explained/) (they have the Hierarchy stuff on the bottom )

---

<div class="post-metadata">

**Author:** ![BA-Quest](https://www.epiusers.help/user_avatar/www.epiusers.help/ba-quest/32/769_2.png) [@BA-Quest](https://www.epiusers.help/u/BA-Quest)\
**Post date:** [February 12, 2019, 12:21am UTC](https://www.epiusers.help/t/cte-based-baq-report/52333/5 "2019-02-12T00:21:28Z")

</div>

@Banderson / @hkeric.wci:

Just reporting back here on my progress so that you know what path I took in this case.

Brandon - I went ahead and scrapped the SSRS report idea because the solution seemed to fit more into the realm of a dynamic dashboard. Sometimes, it’s good to get slapped with the “_Sensibility Stick™_” to get a clearer vision on what might work best. Thanks for your feedback.

Haso - I took your suggestion to maintain the top-level columns and to add in the hierarchy to help with the top-to-bottom and the bottom-to-top sorting, should the user need that capability. It also helped to allow the user a way to “visualize” the hierarchy, as well. I added in a separate Sales Order BAQ to populate and filter when a record with the upper assembly is selected in the “part grid”. The bottom right panel merely maintains the sales orders (_using the same BAQ_) for the originally searched part number.

There were probably easier ways to address this, I’m sure, but this seems to work and the user who requested it was rather pleased.

Example:

 ![cte-hierarchy-example](https://epiusers.help/uploads/default/original/2X/d/d4b01c2b05ac8796c2e1ef790b698ff2850ef217.png)

Thanks again to both of you for getting me over the hump and helping me to provide a workable solution.

I want to give the “mark this as the solution” to both of you, but I’m not sure how to do that in the forum UI 🤔 – but I’m going to attribute it to @Banderson, because he broke me away from the report-based avenue and got me realigned for a proper dashboard solution here (taking nothing away from @hkeric.wci’s contributions here 🤐 )

---

<div class="post-metadata">

**Author:** ![Banderson](https://www.epiusers.help/user_avatar/www.epiusers.help/banderson/32/50875_2.png) [@Banderson](https://www.epiusers.help/u/Banderson)\
**Post date:** [February 12, 2019, 12:24am UTC](https://www.epiusers.help/t/cte-based-baq-report/52333/6 "2019-02-12T00:24:42Z")

</div>

Glad you got it working. I usually find that the dynamic-ness of a dashboard has a lot of value that paper doesn’t (which is one of the reasons I still don’t know hardly anything about SSRS reports 😉). And looking at what you had as example, that doesn’t look that it would do well on paper at all!

---

<div class="post-metadata">

**Author:** ![BA-Quest](https://www.epiusers.help/user_avatar/www.epiusers.help/ba-quest/32/769_2.png) [@BA-Quest](https://www.epiusers.help/u/BA-Quest)\
**Post date:** [February 12, 2019, 12:27am UTC](https://www.epiusers.help/t/cte-based-baq-report/52333/7 "2019-02-12T00:27:40Z")

</div>

Oh, believe me, it didn’t. I thought I could piece together everything with the sales orders all in one shot - but it just wasn’t working. The dashboard was the right call. Besides, it’s easier for the user to employ the “group by” panel and assess the data in any manner he’d like. Thanks again, @Banderson!

---

<div class="post-metadata">

**Author:** ![hkeric.wci](https://www.epiusers.help/user_avatar/www.epiusers.help/hkeric.wci/32/52019_2.png) [@hkeric.wci](https://www.epiusers.help/u/hkeric.wci)\
**Post date:** [February 12, 2019, 12:37pm UTC](https://www.epiusers.help/t/cte-based-baq-report/52333/8 "2019-02-12T12:37:36Z")

</div>

Sometimes its best to give yourself the Solution when unsure 🙂 hehehe. No Worries mate.

Note for anyone reading this… In Order to make my Hierarchy Searchable in a Dashboard… I did add a JobNum: textbox via a Customization and when the User fills it out and Text Changes it populates the Actual Hidden Hierarchy Search field with

```auto
*\word\*
Since its a Matches Field and my Hierarchy is split by Slashes

```

And if Blank then it sets the Hierarchy Field to “”

* * *

Now that you have a BAQ if they ever wanted a Report, you have a better structure to support filtering and sorting and grouping in SSRS.

---

<div class="post-metadata">

**Author:** ![hkeric.wci](https://www.epiusers.help/user_avatar/www.epiusers.help/hkeric.wci/32/52019_2.png) [@hkeric.wci](https://www.epiusers.help/u/hkeric.wci)\
**Post date:** [February 12, 2019, 12:44pm UTC](https://www.epiusers.help/t/cte-based-baq-report/52333/9 "2019-02-12T12:44:53Z")

</div>

[SerialRecursive.baq](https://epiusers.help/uploads/default/original/2X/6/6f6843ee5277f2986cd36ccc45ca4c06b5a65337.baq) (9.1 KB)

If anyone wants Recursvie Serial BAQ =) Something I tinkered with - Shows Matched Serial Numbers

---

<div class="post-metadata">

**Author:** ![jkane](https://www.epiusers.help/user_avatar/www.epiusers.help/jkane/32/57624_2.png) [@jkane](https://www.epiusers.help/u/jkane)\
**Post date:** [July 22, 2020, 5:50pm UTC](https://www.epiusers.help/t/cte-based-baq-report/52333/10 "2020-07-22T17:50:01Z")

</div>

A little late but I just came across this. To do a CTE Recursive query in SSRS, you need to write the query for the dataset in the report as a CTE.
