# SQL Table Date to Date

**URL:** <https://forum.inductiveautomation.com/t/sql-table-date-to-date/18433>\
**Category:** Ignition\
**Created:** [June 12, 2018, 9:16pm UTC](https://forum.inductiveautomation.com/t/sql-table-date-to-date/18433 "2018-06-12T21:16:01Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanastiefes](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@ryanastiefes](https://forum.inductiveautomation.com/u/ryanastiefes)\
**Post date:** [June 12, 2018, 9:16pm UTC](https://forum.inductiveautomation.com/t/sql-table-date-to-date/18433/1 "2018-06-12T21:16:01Z")

</div>

I created a table to showcase some values and would like to filter out data based on two Drop down menu’s which will allow user to see data from a given day to another given day. The drop down menu’s have 1-31 for days. Here is my SQL Query

SELECT Flow, Level, t\_stamp FROM testing WHERE t\_stamp BETWEEN “'2018-6-” + {Root Container.Dropdown 1.selectedValue} + " 00:00:00’" AND “'2018-6-” + {Root Container.Dropdown 3.selectedValue} + " 23:59:00’"

and

SELECT Flow, Level, t\_stamp FROM testing WHERE t\_stamp BETWEEN “'2018-6-” + ‘{Root Container.Dropdown 1.selectedValue}’ + " 00:00:00’" AND “'2018-6-” + ‘{Root Container.Dropdown 3.selectedValue}’ + " 23:59:00’"

This does nothing, but if I take out the dropdown menu’s like this:  
SELECT Flow, Level, t\_stamp FROM testing WHERE t\_stamp BETWEEN ‘2018-6-12 00:00:00’ AND ‘2018-6-12 23:59:00’

it works

Any thoughts?

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [June 12, 2018, 9:31pm UTC](https://forum.inductiveautomation.com/t/sql-table-date-to-date/18433/2 "2018-06-12T21:31:36Z")

</div>

Just use single quotes. Here’s an example I just tested:

```auto
SELECT top 10 *
FROM AUDIT_EVENTS
WHERE EVENT_TIMESTAMP > '2018-6-' + '{Root Container.Dropdown.selectedValue}' + ' 00:00:00'

```

---

<div class="post-metadata">

**Author:** ![ryanastiefes](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@ryanastiefes](https://forum.inductiveautomation.com/u/ryanastiefes)\
**Post date:** [June 12, 2018, 9:34pm UTC](https://forum.inductiveautomation.com/t/sql-table-date-to-date/18433/3 "2018-06-12T21:34:45Z")

</div>

did the between function work for you, using single quotes with the between function doesnt seem to work with me.

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [June 12, 2018, 9:44pm UTC](https://forum.inductiveautomation.com/t/sql-table-date-to-date/18433/4 "2018-06-12T21:44:35Z")

</div>

Yes, just changed my example to BETWEEN and it worked as expected.

---

<div class="post-metadata">

**Author:** ![ryanastiefes](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@ryanastiefes](https://forum.inductiveautomation.com/u/ryanastiefes)\
**Post date:** [June 12, 2018, 9:53pm UTC](https://forum.inductiveautomation.com/t/sql-table-date-to-date/18433/5 "2018-06-12T21:53:50Z")

</div>

is there a better way of looking at data between two different dates? I cannot seem to get thsi query to filter out corrrectly.

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [June 12, 2018, 9:56pm UTC](https://forum.inductiveautomation.com/t/sql-table-date-to-date/18433/6 "2018-06-12T21:56:40Z")

</div>

> [@ryanastiefes](#):
>
> is there a better way of looking at data between two different dates?

Yes, using Calendar controls.

> [@ryanastiefes](#):
>
> I cannot seem to get thsi query to filter out corrrectly.

Post your updated code. It's gotta be close.

---

<div class="post-metadata">

**Author:** ![ryanastiefes](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@ryanastiefes](https://forum.inductiveautomation.com/u/ryanastiefes)\
**Post date:** [June 12, 2018, 10:07pm UTC](https://forum.inductiveautomation.com/t/sql-table-date-to-date/18433/7 "2018-06-12T22:07:28Z")

</div>

SELECT Flow, Level, t\_stamp  
FROM testing  
WHERE t\_stamp  
BETWEEN ‘2018-6-’+’{Root Container.Dropdown 1.selectedValue}’+’ 12:00:00’ AND ‘2018-6-12 14:59:00’

---

<div class="post-metadata">

**Author:** ![ethomason](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ethomason/32/43338_2.png) [@ethomason](https://forum.inductiveautomation.com/u/ethomason)\
**Post date:** [June 12, 2018, 10:37pm UTC](https://forum.inductiveautomation.com/t/sql-table-date-to-date/18433/8 "2018-06-12T22:37:21Z")

</div>

What is the value and type of Root Container.Dropdown 1.selectedValue? Are you receiving any sort of error?

---

<div class="post-metadata">

**Author:** ![ryanastiefes](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@ryanastiefes](https://forum.inductiveautomation.com/u/ryanastiefes)\
**Post date:** [June 12, 2018, 10:43pm UTC](https://forum.inductiveautomation.com/t/sql-table-date-to-date/18433/9 "2018-06-12T22:43:37Z")

</div>

Values are 1-16. No no errors. I am currently trying the calenders and having more success. Code looks correct though, yeah?

---

<div class="post-metadata">

**Author:** ![Stuart](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@Stuart](https://forum.inductiveautomation.com/u/Stuart)\
**Post date:** [June 13, 2018, 12:01am UTC](https://forum.inductiveautomation.com/t/sql-table-date-to-date/18433/10 "2018-06-13T00:01:32Z")

</div>

What if you try using the `.selectedStringValue` property of the dropdown? I suspect there is some problem with **integers** and **strings** be combined.
