Dynamic SQL Select Statement

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

Dynamic SQL Select Statement

Postby ebrandt » Thu May 27, 2004 2:10 pm

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
ebrandt
 
Posts: 590
Joined: Tue Mar 30, 2004 6:54 pm
Location: largo, fl

Postby patrick » Thu May 27, 2004 2:40 pm

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

Code: Select all
var query = 'select * from x where y = ' + somefield


somefield, then, is your dynamic part...
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Postby ebrandt » Thu May 27, 2004 2:53 pm

Thank you
ebrandt
 
Posts: 590
Joined: Tue Mar 30, 2004 6:54 pm
Location: largo, fl

Postby pbakker » Thu May 27, 2004 3:19 pm

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
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 25 guests

cron