# Prepared Statement

**URL:** <https://forum.servoy.com/t/prepared-statement/11303>\
**Category:** Classic Servoy\
**Created:** [October 21, 2009, 7:39pm UTC](https://forum.servoy.com/t/prepared-statement/11303 "2009-10-21T19:39:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gldni](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@gldni](https://forum.servoy.com/u/gldni)\
**Post date:** [October 21, 2009, 7:39pm UTC](https://forum.servoy.com/t/prepared-statement/11303/1 "2009-10-21T19:39:18Z")

</div>

I’m looking over some queries i have written and updating them using prepared statements. I have come across a few scenarios I’m having trouble getting to work. For instance, I have a form variable, search, that users can enter search criteria. Lets say the user inputs the letter “t”. Here is my query:

```auto
var found = "'" + search + "%'";
query = "Select medication_sample_id from medication_samples where medication_name like ? order by medication_name";
dataset = databaseManager.getDataSetByQuery(controller.getServerName(),query,[found],-1);

```

My dataset is empty. But if I do it this way:

```auto
var found = "'" + search + "%'";
query = "Select medication_sample_id from medication_samples where medication_name like " + found + " order by medication_name";
dataset = databaseManager.getDataSetByQuery(controller.getServerName(),query,null,-1);

```

I get the desired results. Can someone show me how to properly structure this prepared statement using LIKE and the % wildcard?

Thanks!  
Nicholas Dunn  
E-Automation Systems

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [October 21, 2009, 9:04pm UTC](https://forum.servoy.com/t/prepared-statement/11303/2 "2009-10-21T21:04:05Z")

</div>

Hi Nicholas,

When you pass a parameter to a prepared statement you don’t pass any quoted strings because the prepared statement will take care of this for you.  
So the following code would do fine:

```auto
var found = search + "%"; // no extra quotes
query = "Select medication_sample_id from medication_samples where medication_name like ? order by medication_name";
dataset = databaseManager.getDataSetByQuery(controller.getServerName(),query,[found],-1);

```

Hope this helps.

---

<div class="post-metadata">

**Author:** ![gldni](https://avatars.discourse-cdn.com/v4/letter/g/7ea924/32.png) [@gldni](https://forum.servoy.com/u/gldni)\
**Post date:** [October 21, 2009, 9:48pm UTC](https://forum.servoy.com/t/prepared-statement/11303/3 "2009-10-21T21:48:46Z")

</div>

Awesome Robert! Thanks for the help!
