# Search for SerialNumber using the same window

**URL:** <https://forum.inductiveautomation.com/t/search-for-serialnumber-using-the-same-window/5055>\
**Category:** Ignition\
**Created:** [August 24, 2012, 8:25pm UTC](https://forum.inductiveautomation.com/t/search-for-serialnumber-using-the-same-window/5055 "2012-08-24T20:25:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bachphi](https://avatars.discourse-cdn.com/v4/letter/b/ccd318/32.png) [@bachphi](https://forum.inductiveautomation.com/u/bachphi)\
**Post date:** [August 24, 2012, 8:25pm UTC](https://forum.inductiveautomation.com/t/search-for-serialnumber-using-the-same-window/5055/1 "2012-08-24T20:25:28Z")

</div>

I have a window that currently display a table and a date-range slide bar.  
Data is displayed from Data properties with SELECT query:

SELECT \*  
FROM MyDB  
WHERE t\_stamp BETWEEN ‘{Root Container.Date Range.startDate}’ AND ‘{Root Container.Date Range.endDate}’

Now I want to add a text box in the same window to search for a particular serial number from the db and display that in the table in the same window.  
If the text box is empty, then display data as normal from time-range. If it’s not empty then search for the serial number.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Travis.Cox](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@Travis.Cox](https://forum.inductiveautomation.com/u/Travis.Cox)\
**Post date:** [August 24, 2012, 9:35pm UTC](https://forum.inductiveautomation.com/t/search-for-serialnumber-using-the-same-window/5055/2 "2012-08-24T21:35:31Z")

</div>

Ok you can do the following:

1. Add a custom property to the text field called “where” that is a string (right click on component and select Customizers \> Custom Properties)
2. Bind the “where” the following expression:`if({Root Container.Text Field.text} = "", "1=1", "Col = '" + escapeSQL({Root Container.Text Field.text}) + "'"`3) Change your query to look like this:`SELECT * 
FROM MyDB
WHERE t_stamp BETWEEN '{Root Container.Date Range.startDate}' AND '{Root Container.Date Range.endDate}' AND {Root Container.Text Field.where}`Hope that helps.

---

<div class="post-metadata">

**Author:** ![bachphi](https://avatars.discourse-cdn.com/v4/letter/b/ccd318/32.png) [@bachphi](https://forum.inductiveautomation.com/u/bachphi)\
**Post date:** [August 25, 2012, 1:14pm UTC](https://forum.inductiveautomation.com/t/search-for-serialnumber-using-the-same-window/5055/3 "2012-08-25T13:14:23Z")

</div>

at step 2, binding the “where” , I needed to add a parenthesis at the end

if ({Root Container.Text Field.text} = “”, “1=1”, “Column2 = '” + escapeSQL({Root Container.Text Field.text}) + “’” )

Not sure what 1=1 is, but it does work!

I added another text box and binded to “where2”, and it works too!.

Thanks much!!

---

<div class="post-metadata">

**Author:** ![Duffanator](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/duffanator/32/3560_2.png) [@Duffanator](https://forum.inductiveautomation.com/u/Duffanator)\
**Post date:** [August 27, 2012, 11:29am UTC](https://forum.inductiveautomation.com/t/search-for-serialnumber-using-the-same-window/5055/4 "2012-08-27T11:29:28Z")

</div>

> [@](#):
>
> Not sure what 1=1 is, but it does work!

That's a way of bypassing the where clause if it's not needed. Since 1 always equals 1 it will bring back everything in that table (if that was the only where clause of course). So, if you need to make a conditional where clause then putting in Where 1=1 if a condition is not met will be a good way of bypassing that where clause, you can't have an empty where clause.

So, in your example if the string is empty then you would make the where clause 1=1 to bring back every row, otherwise you would only bring back rows that had an empty string, which would probably be no rows. Otherwise it will put the contents of your text box in the where clause. Hopefully that makes sense?
