HomeFlySpeed SQL QueryCreate parameters for a query

Create parameters for a query

Is there a way to pass parameters to a query? I use often queries like:

SELECT field1, field2 FROM table WHERE field3 LIKE '%myword%' OR field4 LIKE '%myword%' OR field4 LIKE '%myword%'

and you can guess that it's a nightmare to change the same word in different places
What's about a sort of setting somewhere a parameter like "myword = word1" or "myword = word2" so that the query remains unchanged and I can copy/paste it wherever I need?
An example: I recently used a query like this in a PHP/MySQL project:

SELECT field1, field2 FROM table WHERE field3 LIKE '$user' OR field4 LIKE '$user' OR field4 LIKE '$user'

I had to change "$user" with some real usernames to see if the query was right, and this took me a lot of time
It would have been nice if I could set "$user = John" only once and have it applied in my query... and I could copy/paste my query as is!

Ivan | email
June 9 2011, 09:16 AM
Use the following notation to specify parameters: WHERE Field = :Param.
You may enter parameters to the SQL query text or to the Criteria cells of the Query Builder's columns grid.

On executing such query you will be prompted for parameter values.
Sergey Smagin | email
1 day, 4 hours since original post
Woah! Super! Very handy, once known! Thx!

Stefan_E | email
1 day, 8 hours since original post
Yeah, agree with Stefan!!! Great feature, didn't knew the existence! Thanks
Ivan | email
1 day, 20 hours since original post
Hi Sergey,

seems to work great with select queries, but non-select queries seem to ignore the parameters?

1 week, 2 days since original post
That's right. This feature is provided by the query building component which works with the SELECT statements only.
Sergey Smagin | email
1 week, 4 days since original post
Is there a way to use a parameter in the "IN" predicate?
Doug Smith | email
4 months since original post
This topic is closed