Monday, 2 September 2013

Applying a WHERE after CASE statement?

Applying a WHERE after CASE statement?

I'm using a CASE statement to build my query for some dates filtering, but
after getting the proper CASE syntax, I can't manage to a apply a WHERE
statement.
So, I was wondering, how may I do so?
My actual code is:
SELECT id, fecha_inicio,
CASE WHEN eventos.fecha_fin IS NULL
THEN DATE_ADD(eventos.fecha_inicio, INTERVAL 45 DAY)
ELSE fecha_fin
END as fecha_fin_new
FROM eventos
WHERE DATE_FORMAT(fecha_fin_new, '%Y-%m') >= '2006-01'

No comments:

Post a Comment