# SQL Query to check if data exists

**URL:** <https://forum.inductiveautomation.com/t/sql-query-to-check-if-data-exists/60326>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [June 2, 2022, 11:21pm UTC](https://forum.inductiveautomation.com/t/sql-query-to-check-if-data-exists/60326 "2022-06-02T23:21:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![csilk](https://avatars.discourse-cdn.com/v4/letter/c/9e8a1a/32.png) [@csilk](https://forum.inductiveautomation.com/u/csilk)\
**Post date:** [June 2, 2022, 11:21pm UTC](https://forum.inductiveautomation.com/t/sql-query-to-check-if-data-exists/60326/1 "2022-06-02T23:21:43Z")

</div>

I have a dropdown that is populated through a query and I have “custom options” enabled for the dropdown. Basically, I want to run a query that will check to see if the selected value, of the dropdown, exists in the database (I know that the selected value is not in the DB, but the end user does not). If it does not, I want to show a popup.

My problem is, I can’t get the right SQL query syntax…

When a value is selected from the dropdown, it passes the selected value into parameter “Customer”  
Client is the column I want to search in the table  
The table is called DBTable

Here is my script:

```auto
customer = self.view.params.Customer	
existsInDB = system.db.runScalarQuery("SELECT Client FROM DBTable WHERE Client LIKE '%s'" %customer)
	
if existsInDB == None:
	value = "Not in DB"
else:
	value = "Exists in DB"
return value

```

Until I can get some other things developed and working, I am just displaying “Not in DB” in a text box if the selected value is not in the database and “Exists in DB” if the selected value does exist.

Thank you in advance

---

<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:** [June 2, 2022, 11:49pm UTC](https://forum.inductiveautomation.com/t/sql-query-to-check-if-data-exists/60326/2 "2022-06-02T23:49:39Z")

</div>

I pretty much always use `system.db.runNamedQuery()` but looking at [the documentation](https://docs.inductiveautomation.com/display/DOC81/system.db.runScalarQuery), i believe you need to include the database connection name in your `system.db.runScalarQuery` call.

---

<div class="post-metadata">

**Author:** ![kavya\_shree](https://avatars.discourse-cdn.com/v4/letter/k/b4bc9f/32.png) [@kavya\_shree](https://forum.inductiveautomation.com/u/kavya_shree)\
**Post date:** [December 26, 2022, 11:09am UTC](https://forum.inductiveautomation.com/t/sql-query-to-check-if-data-exists/60326/3 "2022-12-26T11:09:43Z")

</div>

Hi,

I have drop down, **after selecting value from dropdown** , it should check in database if selected value from drop down is exists or not. if exist I need to show pop up saying its already exists.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/5/b562dd0e920480a532d31098c329edb8035c027a.png)

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/b/1bc593d238330b4629856b4e56b1cefeb25b14c5.png)

Here I need to check , selected line=R17 and status= In progress ---\>If present in data base table it should error message.

please suggest script, it will be very helpful.

Thank you.
