Page 1 of 1

Parameterized Querys

Posted: Mon 05 Dec 2005 19:26
by enzers
I have set up a query using the MySQLDataAdapter Editor. The query contains four parameters, though for simplicity I show only two parameters in the following example:

SELECT * FROM Materials WHERE (Type=@Type) AND (Material=@Material)

When using the query, there are times when I want to specify only one parameter. Is there any way to set the unused parameter to the equivalent of a wildcard character so it accepts all values? If I leave the parameter blank or set it to Nothing I get zero results from the query.

Posted: Tue 06 Dec 2005 14:50
by Serious
There are two solutions of your problem.
First, you can use 'LIKE' clause. For additional information refer to MySQL documentation.
Second, you can use additional parameter to indicate that main parameter is not used.

Code: Select all

SELECT * FROM Materials WHERE (Type=:Type) AND (:IgnoreMaterial=1 or Material=:Material)
If you want to ignore 'Material' parameter just set 'IgnoreMaterial' = 1, if you don't, set 'IgnoreMaterial' = 0.