SQL Query to check if data exists

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:

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"
	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

I pretty much always use system.db.runNamedQuery() but looking at the documentation, i believe you need to include the database connection name in your system.db.runScalarQuery call.


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.


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.