I am tasked with creating a way to display information from JobHead, JobOper, JobOpDtl, and PartTran.
The user will select a Resource Group from a combo box (easy enough done), and then get a listing of all operations that are scheduled out between GETDATE() and 2 weeks. That is easy. The hard part comes into play when I need to get a COUNT of all PartTran against the part referenced in each op that is returned. (I also have 2 other nested queries for PartTran, but getting past 1 will allow me to do the other 2 with ease)
So I whipped up a fairly basic SQL query that works great in SQL Studio and I am trying to turn into a BAQ. However I have having issues on the âSELECT COUNT(*)â line when I try to set it as a calculated field.
SELECT
JobOpDtl.ResourceGrpID,
JobOper.JobNum,
JobHead.PartNum,
JobHead.PartDescription,
JobOper.StartDate,
JobOper.CommentText,
( SELECT
COUNT(*) AS [TransCount]
FROM
Erp.PartTran
WHERE
PartTran.PartNum = JobHead.PartNum)
AS [TransCount]
FROM
Erp.JobOper JobOper
INNER JOIN
Erp.JobHead
ON JobOper.Company = JobHead.Company
AND JobOper.JobNum = JobHead.JobNum
INNER JOIN
Erp.JobOpDtl JobOpDtl
ON JobOper.Company = JobOpDtl.Company
AND JobOper.JobNum = JobOpDtl.JobNum
AND JobOper.AssemblySeq = JobOpDtl.AssemblySeq
AND JobOper.OprSeq = JobOpDtl.OprSeq
WHERE
DATEDIFF(WEEK, JobOper.StartDate, GETDATE()) BETWEEN 0 AND 2
AND JobOpDtl.ResourceGrpID = '@ResGrpID_Param'
AND JobHead.JobReleased = 1
ORDER BY
JobOper.StartDate
When I try to add that âSELECT COUNTâ from PartTran as a Calculated Field, I get the error below:
Now I get that the error is being thrown due to a possible unauthorized query being present. What I donât get, however, is a potential workaround.
Can I do the PartTran column as a subquery and pass the PartNum value from the main query to it as a parameter? I know I could just run the PartTran query seperately and filter it after-the-fact, but that is a lot of overhead.
I also looked into do this as a UD, but as far as I can see, there is no way to combine multiple adapters for a query. (IE: PartTran and JobOp). If it was considered âkosherâ to do this via a customization where I query the DB directly, I would. But, that is frowned upon and I would like to do it in an approved fashion.