I have an html5 query that works fine like this:
tx.executeSql('SELECT *
FROM bdreminders
WHERE firstname = IFNULL(?, firstname)
AND lastname = IFNULL(?, lastname)
AND baughtgift = IFNULL(?, baughtgift)
ORDER BY firstname asc',
[passedfn,passedln,passedbg],renderFunc,birthdayapp.onError);
However, I want to use the “like” operator instead of “=” but do not know how to implement it using IFNULL.
If you simply replace the ‘=’ with a LIKE operator, you will get the same exact match answer as your current query. I assume you would like to use the LIKE operator to do something different (such as a begins with search).
I provided you how SQL databases normally does this, but if this works for you depends on how SQL compatible the SQL dialect being used by the HTML5 engine is.
Firstly, it depends on concaternation syntax. Secondly, it depends on concaternation using NULL + string produces NULL or the string. Most professional databases would yield NULL (this is good for you, because then this will work).
The following should work on MySQL or Oracle and some other databases:
or (for Oracle, Postgre and others)
or (for SQL server and others)
I would try the last one first. If the above does not work and you get all bdreminders, the database does not concaternate NULL+string to NULL. In this case, I don’t think you can use ISNULL as it will return the first non null value and thus, always return ‘%’.