# Subquery on InvcDtl to InvMisc

**URL:** <https://www.epiusers.help/t/subquery-on-invcdtl-to-invmisc/52769>\
**Category:** Epicor ERP 10\
**Tags:** baq\
**Created:** [February 19, 2019, 8:39pm UTC](https://www.epiusers.help/t/subquery-on-invcdtl-to-invmisc/52769 "2019-02-19T20:39:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adam](https://www.epiusers.help/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@Adam](https://www.epiusers.help/u/Adam)\
**Post date:** [February 19, 2019, 8:39pm UTC](https://www.epiusers.help/t/subquery-on-invcdtl-to-invmisc/52769/1 "2019-02-19T20:39:52Z")

</div>

Having a hard time with a subquery. I am trying to return a “modified line total” as ExtendedPrice + MiscChrg (but, MiscChrg needs to be based on only certain MiscCodes, requiring a subquery).

I added the InvcDtl table to my query with an InnerSubQuery connected to InvcMisc on Company, InvoiceNum, InvoiceLine. In this subquery I display (grouped by) Company, InvoiceNum, and InvoiceLine, along with a calc field for sum of MiscChrg (the table criteria selects the MiscCode we need).

Now, the issue: For each InvcDtl result that has a value in the subquery, my “modified line total” returns as desired. HOWEVER, for each result that has a null in the subquery, the modified line total simply displays a blank.

My modified line total calc looks like: InvcDtl.ExtPrice + SubQuery2.Calculated\_TotalMiscChrg

Any thoughts?

---

<div class="post-metadata">

**Author:** ![Adam](https://www.epiusers.help/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@Adam](https://www.epiusers.help/u/Adam)\
**Post date:** [February 19, 2019, 8:48pm UTC](https://www.epiusers.help/t/subquery-on-invcdtl-to-invmisc/52769/2 "2019-02-19T20:48:09Z")

</div>

The relationship between InvcDtl and Subquery is “All rows from InvcDtl”. The calc:

`InvcDtl.ExtPrice + SubQuery2.Calculated_TotalMiscChrg`

displays a blank whenever the Subquery returns a null value for Calculate\_TotalMiscChrg.

---

<div class="post-metadata">

**Author:** ![Adam](https://www.epiusers.help/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@Adam](https://www.epiusers.help/u/Adam)\
**Post date:** [February 19, 2019, 9:31pm UTC](https://www.epiusers.help/t/subquery-on-invcdtl-to-invmisc/52769/3 "2019-02-19T21:31:34Z")

</div>

In my calculated field I needed to add a null check:

`InvcDtl.ExtPrice + isnull(SubQuery2.Calculated_TotalMiscChrg, 0)`
