I have such code:
(on RoR):
@types = Type.where("TYP_MOD_ID = ? AND (SUBSTRING(TYP_PCON_START,1,4) <= ?) AND (SUBSTRING(TYP_PCON_END,1,4) >= ?) AND TYP_KV_FUEL_DES_ID = ? ", params[:models], params[:year], params[:year], params[:fueltype]).order("TYP_HP_FROM")
But sometimes TYP_PCON_END is null in db…. How in such case use not null, but my value, sended by ruby (date.now(YEAR))?
So how if field is null use another value?
How to check on null, and use my code if not null (SUBSTRING(TYP_PCON_END,1,4) >= ?)
and another:
? >= ?
if null?
You can use
COALESCE:If you don’t need the substring for your default value, then you would just do it this way:
This works since doing a
SUBSTRINGon a null value will yield null as well.