select
ev.iEventId, ev.iEntityId, ev.chAssignedTo, ev.iSourceId,
ev.iStatusId, ev.dtInsertDate,
case
when ev.dtinsertdate > DATEADD(ms,-30,ev.dtinsertdate)
then ev.dtInsertDate
else DATEADD(hh, 3, ev.dtInsertDate)
end
from
event ev WITH(NOLOCK)
left join
vehicle v WITH(NOLOCK) on ev.iEventId = v.iSalesNo
and v.tiRecordStatus = 1
and v.iSiteId = 1359
and ev.iSiteId = 1359
and ev.tiRecordStatus = 1
and ev.iEventCategory = 1
and ev.iStatusId <> 0