# Making SQL code into BAQ

**URL:** <https://www.epiusers.help/t/making-sql-code-into-baq/109834>\
**Category:** Epicor ERP 10\
**Tags:** baq, e10, epicor\
**Created:** [December 8, 2023, 7:56pm UTC](https://www.epiusers.help/t/making-sql-code-into-baq/109834 "2023-12-08T19:56:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![LexLawnjac](https://www.epiusers.help/letter_avatar_proxy/v4/letter/l/6f9a4e/32.png) [@LexLawnjac](https://www.epiusers.help/u/LexLawnjac)\
**Post date:** [December 8, 2023, 7:56pm UTC](https://www.epiusers.help/t/making-sql-code-into-baq/109834/1 "2023-12-08T19:56:07Z")

</div>

Hey guys,  
I am trying to get this SQL code into a BAQ. Any help would be appreciated.

with LaborData as(  
SELECT  
a.EmployeeNum,  
Cast(a.ClockInDate as smalldatetime) as ClockInTime,  
a.LaborHrs,  
a.ExpenseCode,  
a.IndirectCode,  
a.JobNum,  
b.Name,  
a.LaborNote  
FROM ERP21Live.erp.LaborDtl a  
left outer join erp.EmpBasic b  
on a.Company= b.Company  
and a.EmployeeNum = b.EmpID  
WHERE a.Company=‘PPI’ AND a.ClockInDate\>=‘1/1/2023’ and a.EmployeeNum in (‘sagb’,‘smb’,‘brb’,‘jlb2’) --and a.LaborNote \<\> ‘BREAK-TIME’ AND a.JobNum=‘’  
)

select  
a.Name,

sum(a.LaborHrs) as DirectHrs

from LaborData a  
where a.IndirectCode \<\> ‘IDLE’  
group by a.Name

---

<div class="post-metadata">

**Author:** ![timshuwy](https://www.epiusers.help/user_avatar/www.epiusers.help/timshuwy/32/90122_2.png) [@timshuwy](https://www.epiusers.help/u/timshuwy)\
**Post date:** [December 8, 2023, 8:24pm UTC](https://www.epiusers.help/t/making-sql-code-into-baq/109834/2 "2023-12-08T20:24:48Z")

</div>

seems fairly simple in a baq… You need to add the appropriate tables, add the criteria, and the display fields… you need to mark the group-by for all the fields except for the calculated field that does the SUM of the Labor Hours.

Note that you also have to join the EmpBasic table to the LaborDtl table to get the employee name that you desired to be displayed.

 ![image](https://www.epiusers.help/uploads/default/original/3X/5/3/534a4b037f5750dd1ffedbf564d4378e02450323.png)

THEN add the fields you want to see in the Display FIelds section, but make sure that you do the calculated field for the value you want to sum:

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

Here is the calculated field:

 ![image](https://www.epiusers.help/uploads/default/original/3X/9/a/9aaf03ea58716a3c5cab37f817bc1ad8cacd99ed.png)

---

<div class="post-metadata">

**Author:** ![LexLawnjac](https://www.epiusers.help/letter_avatar_proxy/v4/letter/l/6f9a4e/32.png) [@LexLawnjac](https://www.epiusers.help/u/LexLawnjac)\
**Post date:** [December 8, 2023, 8:29pm UTC](https://www.epiusers.help/t/making-sql-code-into-baq/109834/3 "2023-12-08T20:29:17Z")

</div>

I will be adding a few more table. I was trying to figure out how to get the baq to say  
With LaborData as

Just figured out it is with CTE Query. The group by is a big help though. Had not figured that out yet.
