# BAQ Assistance

**URL:** <https://www.epiusers.help/t/baq-assistance/67083>\
**Category:** Epicor ERP 10\
**Tags:** baq, e10\
**Created:** [May 11, 2020, 12:40pm UTC](https://www.epiusers.help/t/baq-assistance/67083 "2020-05-11T12:40:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dgreenEA](https://www.epiusers.help/user_avatar/www.epiusers.help/dgreenea/32/22635_2.png) [@dgreenEA](https://www.epiusers.help/u/dgreenEA)\
**Post date:** [May 11, 2020, 12:40pm UTC](https://www.epiusers.help/t/baq-assistance/67083/1 "2020-05-11T12:40:45Z")

</div>

I have a BAQ that works throughout most of the week, but every Sunday through Monday it seems to just freeze and I cannot figure out where or why. I have troubleshot this thing, subquery by subquery. Everything seems to be working just fine until we hit the top level and then it just times out. I have adjusted the timeout for it to be 500000 ms, but it gives the below timeout message:

 ![image](https://epiusers.help/uploads/default/original/3X/0/7/0717b0a0f7502e247a6bf059f14881fea0a455b8.png)

Funny thing is if I wait till Tuesday it works just fine the rest of the week. Below is the phrase build. Any and all assistance is appreciated.

/\*

- Disclaimer!!!
- This is not a real query being executed, but a simplified version for general vision.
- Executing it with any other tool may produce a different result.  
\*/

select  
[SubQuery4].[LaborHed\_Company] as [LaborHed\_Company],  
(isnull(sum(SubQuery5.Calculated\_Calc\_LaborHrs),0)) as [Calculated\_SumLbrHrs],  
(isnull(sum(SubQuery4.Calculated\_Sum\_PayHrs),0)) as [Calculated\_SumPayHrs],  
[SubQuery4].[EmpBasic3\_JCDept] as [EmpBasic3\_JCDept],  
[SubQuery4].[LaborHed\_PayrollDate] as [LaborHed\_PayrollDate],  
[SubQuery4].[EmpBasic3\_Name] as [EmpBasic3\_Name],  
(isnull(sum(YearIndHrs2.Calculated\_SumYearIndHrs),0)) as [Calculated\_SumIndHrs]  
from (select  
(sum(LaborHed.PayHours)) as [Calculated\_Sum\_PayHrs],  
[LaborHed].[Company] as [LaborHed\_Company],  
[EmpBasic3].[JCDept] as [EmpBasic3\_JCDept],  
[LaborHed].[PayrollDate] as [LaborHed\_PayrollDate],  
[EmpBasic3].[Name] as [EmpBasic3\_Name]  
from Erp.LaborHed as LaborHed  
inner join Erp.EmpBasic as EmpBasic3 on  
LaborHed.Company = EmpBasic3.Company  
and LaborHed.EmployeeNum = EmpBasic3.EmpID  
and ( not EmpBasic3.JCDept = ‘Admin’ and not EmpBasic3.JCDept = ‘ProdSupp’ and EmpBasic3.EmpStatus = ‘A’ and not EmpBasic3.JCDept = ‘Office’ and not EmpBasic3.JCDept = ‘Maint’ and not EmpBasic3.JCDept = ‘AEG’ )

where (LaborHed.PayrollDate \>= DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0) and not LaborHed.EmployeeNum = ‘000120’ and not LaborHed.EmployeeNum = ‘000123’ and not LaborHed.EmployeeNum = ‘000132’ and not LaborHed.EmployeeNum = ‘000102’ and not LaborHed.EmployeeNum = ‘000202’ and not LaborHed.EmployeeNum = ‘010039’ and not LaborHed.EmployeeNum = ‘010117’ and not LaborHed.EmployeeNum = ‘010132’ and not LaborHed.EmployeeNum = ‘010203’ and not LaborHed.EmployeeNum = ‘010147’ and not LaborHed.EmployeeNum = ‘010224’ and not LaborHed.EmployeeNum = ‘010199’ and not LaborHed.EmployeeNum = ‘010165’ and not LaborHed.EmployeeNum = ‘010006’ and not LaborHed.EmployeeNum = ‘010211’ and not LaborHed.EmployeeNum = ‘010123’ and not LaborHed.EmployeeNum = ‘010201’ and not LaborHed.EmployeeNum = ‘010186’)  
group by [LaborHed].[Company],  
[EmpBasic3].[JCDept],  
[LaborHed].[PayrollDate],  
[EmpBasic3].[Name]) as SubQuery4  
left outer join (select  
(sum(LaborDtl.LaborHrs)) as [Calculated\_Calc\_LaborHrs],  
[LaborDtl].[Company] as [LaborDtl\_Company],  
[EmpBasic2].[JCDept] as [EmpBasic2\_JCDept],  
[LaborDtl].[PayrollDate] as [LaborDtl\_PayrollDate],  
[EmpBasic2].[Name] as [EmpBasic2\_Name]  
from Erp.LaborDtl as LaborDtl  
inner join Erp.EmpBasic as EmpBasic2 on  
LaborDtl.Company = EmpBasic2.Company  
and LaborDtl.EmployeeNum = EmpBasic2.EmpID  
and ( not EmpBasic2.JCDept = ‘Admin’ and not EmpBasic2.JCDept = ‘ProdSupp’ and EmpBasic2.EmpStatus = ‘A’ )

where (LaborDtl.LaborType \<\> ‘I’ and LaborDtl.PayrollDate \>= DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0) and not LaborDtl.EmployeeNum = ‘000120’ and not LaborDtl.EmployeeNum = ‘000123’ and not LaborDtl.EmployeeNum = ‘000132’ and not LaborDtl.EmployeeNum = ‘000102’ and not LaborDtl.EmployeeNum = ‘000202’ and not LaborDtl.EmployeeNum = ‘010039’ and not LaborDtl.EmployeeNum = ‘010117’ and not LaborDtl.EmployeeNum = ‘010132’ and not LaborDtl.EmployeeNum = ‘010203’ and not LaborDtl.EmployeeNum = ‘010147’ and not LaborDtl.EmployeeNum = ‘010224’ and not LaborDtl.EmployeeNum = ‘010199’ and not LaborDtl.EmployeeNum = ‘010165’ and not LaborDtl.EmployeeNum = ‘010006’ and not LaborDtl.EmployeeNum = ‘010211’ and not LaborDtl.EmployeeNum = ‘010123’ and not LaborDtl.EmployeeNum = ‘010201’ and not LaborDtl.EmployeeNum = ‘010186’)  
group by [LaborDtl].[Company],  
[EmpBasic2].[JCDept],  
[LaborDtl].[PayrollDate],  
[EmpBasic2].[Name]) as SubQuery5 on  
SubQuery4.LaborHed\_Company = SubQuery5.LaborDtl\_Company  
and SubQuery4.EmpBasic3\_JCDept = SubQuery5.EmpBasic2\_JCDept  
and SubQuery4.LaborHed\_PayrollDate = SubQuery5.LaborDtl\_PayrollDate  
and SubQuery4.EmpBasic3\_Name = SubQuery5.EmpBasic2\_Name  
left outer join (select  
[LaborDtl2].[PayrollDate] as [LaborDtl2\_PayrollDate],  
[LaborDtl2].[Company] as [LaborDtl2\_Company],  
[EmpBasic4].[JCDept] as [EmpBasic4\_JCDept],  
[EmpBasic4].[Name] as [EmpBasic4\_Name],  
(sum(LaborDtl2.LaborHrs)) as [Calculated\_SumYearIndHrs],  
[LaborDtl2].[EmployeeNum] as [LaborDtl2\_EmployeeNum],  
[EmpBasic4].[EmpID] as [EmpBasic4\_EmpID]  
from Erp.LaborDtl as LaborDtl2  
inner join Erp.EmpBasic as EmpBasic4 on  
LaborDtl2.Company = EmpBasic4.Company  
and LaborDtl2.EmployeeNum = EmpBasic4.EmpID  
and ( not EmpBasic4.JCDept = ‘Admin’ and not EmpBasic4.JCDept = ‘ProdSupp’ and EmpBasic4.EmpStatus = ‘A’ )

where (LaborDtl2.LaborType = ‘I’ and not LaborDtl2.IndirectCode = ‘IDLE’ and LaborDtl2.PayrollDate \>= DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0) and not LaborDtl2.IndirectCode = ‘IND’)  
group by [LaborDtl2].[PayrollDate],  
[LaborDtl2].[Company],  
[EmpBasic4].[JCDept],  
[EmpBasic4].[Name],  
[LaborDtl2].[EmployeeNum],  
[EmpBasic4].[EmpID]) as YearIndHrs2 on  
YearIndHrs2.EmpBasic4\_JCDept = SubQuery4.EmpBasic3\_JCDept  
and YearIndHrs2.EmpBasic4\_Name = SubQuery4.EmpBasic3\_Name  
and YearIndHrs2.LaborDtl2\_Company = SubQuery4.LaborHed\_Company  
and YearIndHrs2.LaborDtl2\_PayrollDate = SubQuery4.LaborHed\_PayrollDate  
group by [SubQuery4].[LaborHed\_Company],  
[SubQuery4].[EmpBasic3\_JCDept],  
[SubQuery4].[LaborHed\_PayrollDate],  
[SubQuery4].[EmpBasic3\_Name]

---

<div class="post-metadata">

**Author:** ![markdamen](https://www.epiusers.help/user_avatar/www.epiusers.help/markdamen/32/54917_2.png) [@markdamen](https://www.epiusers.help/u/markdamen)\
**Post date:** [May 11, 2020, 12:50pm UTC](https://www.epiusers.help/t/baq-assistance/67083/2 "2020-05-11T12:50:07Z")

</div>

Once the query has run within BAQ Designer, from the Actions menu you get the Query Execution Plan.

Download this file, and then open it using SQL Server Management Studio. It will highlight where the majority of the time is being spent. You can then look to improve the query in Epicor, or consider adding an index as suggested by the query plan analysis.

The trick is to try and hit Epicor native indexes - an example might be where you’re limiting based upon EmployeeNum, which doesn’t hit an index. If you add in another filter to check for Company = BAQ.CurComp then it might hit the default index and return results much quicker.

---

<div class="post-metadata">

**Author:** ![dgreenEA](https://www.epiusers.help/user_avatar/www.epiusers.help/dgreenea/32/22635_2.png) [@dgreenEA](https://www.epiusers.help/u/dgreenEA)\
**Post date:** [May 11, 2020, 1:36pm UTC](https://www.epiusers.help/t/baq-assistance/67083/3 "2020-05-11T13:36:29Z")

</div>

@markdamen,

I’ll work towards getting those optimizations made. In the mean time, is there something else I can do in order to increase timeout time? I guess I’m just confused as to why the query execution time isn’t matching what I set it too, 30k ms vs 500kms. I am on gov cloud if that info changes anything.

---

<div class="post-metadata">

**Author:** ![markdamen](https://www.epiusers.help/user_avatar/www.epiusers.help/markdamen/32/54917_2.png) [@markdamen](https://www.epiusers.help/u/markdamen)\
**Post date:** [May 11, 2020, 4:09pm UTC](https://www.epiusers.help/t/baq-assistance/67083/4 "2020-05-11T16:09:11Z")

</div>

When you made that change, you set it to “persist in query”? Otherwise, it would apply for the BAQ Designer session but then be lost when it runs for real or you reload the designer.

In the Epicor Admin Console which you don’t have access to, there is also a setting regards BAQ execution. I’m not sure what the hierarchy is of how the 2 settings are applied, but it this:

![image](https://epiusers.help/uploads/default/original/3X/e/3/e3fb68bec4c5a581f31c79836c45c93d7eb1081f.png)

You could raise a ticket and see if they have 30 seconds configured here?

---

<div class="post-metadata">

**Author:** ![dgreenEA](https://www.epiusers.help/user_avatar/www.epiusers.help/dgreenea/32/22635_2.png) [@dgreenEA](https://www.epiusers.help/u/dgreenEA)\
**Post date:** [May 11, 2020, 6:36pm UTC](https://www.epiusers.help/t/baq-assistance/67083/5 "2020-05-11T18:36:20Z")

</div>

@markdamen,

I had it set to persist in query. I submitted a ticket to see if the cloud team will extend the timeout for me as well. Waiting for a response. Thanks for the help!
