# SQL help, organizing some user input data with automatic data over shifts

**URL:** <https://forum.inductiveautomation.com/t/sql-help-organizing-some-user-input-data-with-automatic-data-over-shifts/58325>\
**Category:** Ignition\
**Created:** [April 11, 2022, 8:32pm UTC](https://forum.inductiveautomation.com/t/sql-help-organizing-some-user-input-data-with-automatic-data-over-shifts/58325 "2022-04-11T20:32:39Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [April 14, 2022, 6:00pm UTC](https://forum.inductiveautomation.com/t/sql-help-organizing-some-user-input-data-with-automatic-data-over-shifts/58325/21 "2022-04-14T18:00:34Z")

</div>

I think it is done for now.

MS SQL  
it is a named query

```auto
Row_Number() over (partition by particularMachine order by Hours desc) as particularMachine2,

```

now I see an error, instead of hours, should prob be t\_stamp

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [April 14, 2022, 6:29pm UTC](https://forum.inductiveautomation.com/t/sql-help-organizing-some-user-input-data-with-automatic-data-over-shifts/58325/22 "2022-04-14T18:29:28Z")

</div>

> [@zacharyw.larson](#):
>
> In order to get the decimals point values on the division for showing percentages.  
> Both are integers.

Should not be necessary to cast as float to get decimals, though not like you'll see any difference in performance.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/b/4be0456f8390d7fddb4692f7430bb3726abd9308.png)

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [April 14, 2022, 6:39pm UTC](https://forum.inductiveautomation.com/t/sql-help-organizing-some-user-input-data-with-automatic-data-over-shifts/58325/23 "2022-04-14T18:39:55Z")

</div>

was rounding out decimals when I had them as integers

not sure

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [April 14, 2022, 8:10pm UTC](https://forum.inductiveautomation.com/t/sql-help-organizing-some-user-input-data-with-automatic-data-over-shifts/58325/24 "2022-04-14T20:10:06Z")

</div>

I am having an issue with the join.

I was using left join.

autoTable has results for a shift  
manualTable skipped that shift  
every join I try, I get no values from the autoTable for that shift though

in the join I have similar to:  
` autoTable.shift = manualTable.shift`

So I thought join outer would show me left table entries and nulls in the right table columns

If I remove the shift match, then I see values, but they match incorrectly

* * *

I think I am going to do a ticket.  
Probably something in there that is obvious if I could show the whole query as it is.

* * *

figured it out,  
was filtering in where by hours\>0, and that comes form right side table

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [April 15, 2022, 12:14pm UTC](https://forum.inductiveautomation.com/t/sql-help-organizing-some-user-input-data-with-automatic-data-over-shifts/58325/25 "2022-04-15T12:14:36Z")

</div>

Can you use [https://www.db-fiddle.com/](https://www.db-fiddle.com/) - recreate your table schemas and add some fake data, click save, and then post the link - it will allow us to actually play with your tables. Well make it a lot easier to help you with your query as right now we are doing it blind - we don’t know what your schema is or how the table relate exactly etc.

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [April 18, 2022, 12:43pm UTC](https://forum.inductiveautomation.com/t/sql-help-organizing-some-user-input-data-with-automatic-data-over-shifts/58325/26 "2022-04-18T12:43:00Z")

</div>

how does that site work?  
I prob can, does it save subsets of data and querie somehow or is it just like going to be wiped out when you leave it?

---

<div class="post-metadata">

**Author:** ![Zach\_Larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zach_larson/32/54388_2.png) [@Zach\_Larson](https://forum.inductiveautomation.com/u/Zach_Larson)\
**Post date:** [February 13, 2024, 1:44pm UTC](https://forum.inductiveautomation.com/t/sql-help-organizing-some-user-input-data-with-automatic-data-over-shifts/58325/27 "2024-02-13T13:44:10Z")

</div>

Oh my query above was such a work around.

I was using subqueries, unions, groups, and cases much more effectively just a few months later that same year even. That query above is so embarrassing now.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [February 13, 2024, 2:21pm UTC](https://forum.inductiveautomation.com/t/sql-help-organizing-some-user-input-data-with-automatic-data-over-shifts/58325/28 "2024-02-13T14:21:37Z")

</div>

> [@Zach\_Larson](#):
>
> That query above is so embarrassing now.

Nah.... Just a sign of growth and that is a positive not a negative. Perhaps it was a _work_around, but that just means you were able to find a solution.

Two signs of a good engineer is being able to solve a problem despite not having the prerequisite knowledge, and recognizing that is also a problem and taking the opportunity to grow.

[Previous page](https://forum.inductiveautomation.com/t/sql-help-organizing-some-user-input-data-with-automatic-data-over-shifts/58325.md?page=1)
