# Dynamic SQL Select Statement

**URL:** <https://forum.servoy.com/t/dynamic-sql-select-statement/1939>\
**Category:** Classic Servoy\
**Created:** [May 27, 2004, 12:10pm UTC](https://forum.servoy.com/t/dynamic-sql-select-statement/1939 "2004-05-27T12:10:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebrandt](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@ebrandt](https://forum.servoy.com/u/ebrandt)\
**Post date:** [May 27, 2004, 12:10pm UTC](https://forum.servoy.com/t/dynamic-sql-select-statement/1939/1 "2004-05-27T12:10:51Z")

</div>

This is just a conceptual question,

I have created methods that run SELECT statements and return the data set formated with html. This work great for predetermined critera when running complex or extenive reports.

Is it possible to pass a variable into the select statement?

I want the user to be able to enter criteria such as a date range, to return the data set.

I don’t need any in depth responce, I just want to make sure I can accomplish this while I am testing all the functions I will need for my solution. I will most likely not dig into this issue for a few more weeks (If it is possible)

Thankx,  
Erich

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [May 27, 2004, 12:40pm UTC](https://forum.servoy.com/t/dynamic-sql-select-statement/1939/2 "2004-05-27T12:40:09Z")

</div>

yes, that is no problem. Just build your statement like this:

```auto
var query = 'select * from x where y = ' + somefield

```

somefield, then, is your dynamic part…

---

<div class="post-metadata">

**Author:** ![ebrandt](https://avatars.discourse-cdn.com/v4/letter/e/96bed5/32.png) [@ebrandt](https://forum.servoy.com/u/ebrandt)\
**Post date:** [May 27, 2004, 12:53pm UTC](https://forum.servoy.com/t/dynamic-sql-select-statement/1939/3 "2004-05-27T12:53:58Z")

</div>

Thank you

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [May 27, 2004, 1:19pm UTC](https://forum.servoy.com/t/dynamic-sql-select-statement/1939/4 "2004-05-27T13:19:44Z")

</div>

Also have a look at the SQL generator in the CRM demo. It’s a good example of dynamically building SQL statements.

since the SQL statement is just a textstring, you can use all text string tools available, to dynamically build the SQL statement.

Paul
