SELECT 
	DATE_FORMAT(CONVERT_TZ(e.EventTimeStamp, '+00:00', '-05:00'), '%m/%d/%Y %h:%i:%s %p') eventTime, 
	e.SourceName as SourceName, 
	e.Message as DisplayPath,
	REVERSE(INSERT(Reverse(Trim(CONCAT(CASE WHEN e.Active <> 0 THEN "Active, " ELSE "" END, CASE WHEN e.Acked <> 0 THEN "Acknowledged, " ELSE "" END, CASE WHEN e.Suppressed <> 0 THEN "Suppressed, " ELSE "" END, CASE WHEN e.Shelved <> 0 THEN "Shelved, " ELSE "" END))), 1, 1, "")) as States, 
	CASE WHEN e.Priority = 0 THEN 'Diagnostic' WHEN e.Priority = 1 THEN 'Low' WHEN e.Priority = 2 THEN 'Medium' WHEN e.Priority = 3 THEN 'High' WHEN e.Priority = 4 THEN 'Critical' ELSE '' END Priority,
	e.Tag1Value eventValue,
	e.PersonID as ackUser
FROM 
	allevent e
WHERE 
	e.EventTimeStamp BETWEEN :startDate AND :endDate AND Priority BETWEEN :minPriority AND :maxPriority AND
	((:active AND e.Active = True) OR (:ack AND e.Acked = True))
ORDER BY e.EventTimeStamp DESC
LIMIT :limit