I am hung up on how to handle the IFNULL() in both the select and where clauses of this.
I know that HQL provides COALESCE() instead but I'm not sure how to proceed w.r.t. criteria.
sql.eachRow("""SELECT DISTINCT cl.name, b.title, b.type, cb.region, IFNULL(cb.start, c.start),IFNULL(cb.end, c.end)
FROM table.C_B cb
JOIN table.B b on b.id = cb.B_id
JOIN table.C c on c.id = cb.C_id
JOIN table.CL cl on cl.id = c.CL_id
WHERE cb.status='active' AND
DATEDIFF(IFNULL(cb.start, c.start),'""" + startmonth + """') <=0
AND DATEDIFF(IFNULL(cb.end, c.end),'""" + startmonth + """') >0 order by cl.name, b.title"""
) {row ->
str.append('<tr>')
(0..3).each {str.append('<td>' + row[it] + '</td>')}
(4..5).each {str.append('<td>' + String.format('%tY/%<tm/%<td', row[it]) + '</td>')}
str.append('</tr>')
}
Is sqlProjection the way forward?