# Named Query Script to Add Column Values from a DB Table with Null Rows

**URL:** <https://forum.inductiveautomation.com/t/named-query-script-to-add-column-values-from-a-db-table-with-null-rows/83988>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [January 9, 2024, 5:53pm UTC](https://forum.inductiveautomation.com/t/named-query-script-to-add-column-values-from-a-db-table-with-null-rows/83988 "2024-01-09T17:53:00Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 10, 2024, 5:26pm UTC](https://forum.inductiveautomation.com/t/named-query-script-to-add-column-values-from-a-db-table-with-null-rows/83988/12 "2024-01-10T17:26:41Z")

</div>

There was an example of the GROUP BY in my original post.

```auto
SELECT Reason, SUM([DTMIN])
FROM vwIG_DownTimeDetailsByPID
WHERE Reason = 'Electrical'
  AND (
    ([Trans Date] BETWEEN '2024-01-02'AND '2024-01-09')
    OR ([Trans Date] BETWEEN '2024-01-02' AND '2024-01-09')
    OR ([Trans Date] <= '2024-01-02' AND [Trans Date] >= '2024-01-09')
  )
GROUP BY Reason

```

See also, [Wiki - how to post code on this forum](https://forum.inductiveautomation.com/t/wiki-how-to-post-code-on-this-forum/77831)

---

_[View the full topic](https://forum.inductiveautomation.com/t/named-query-script-to-add-column-values-from-a-db-table-with-null-rows/83988)._
