I'm trying to build a query that takes some input parameters. Few things to note...
- Not all parameters are required to be passed to the query.
- If a parameter is not going to be passed to the query, must it still be passed anyway but as
NULL
? - If a parameter is not passed, how would I build it to not include the parameter?
So say you have...
IN name VARCHAR(30),
IN age VARCHAR(2),
IN address VARCHAR(50)
And you only want to search by name...
SELECT * FROM Table WHERE
(
NAME LIKE CONCAT(name, '%')
);
This doesn't seem to work because the age wasn't passed in. Or what if the name was passed in and the address but not the age? How would I build that?