The following code counts how many SLA (time we have to respond to a call) met this week but the query is slow to run....SELECT COUNT(c.id) as slaweek FROM faultlog as c INNER JOIN contact ON c.contid=contact.id WHERE logged>=dateadd(week,datediff(week,0,getdate()),0) AND logged<dateadd(week,datediff(week,0,getdate())+1,0) AND response>datediff(hour,logged,(SELECT TOP 1 date FROM notes WHERE id=c.id AND id_prefix=c.id_prefix ORDER BY date ASC))
The following code is faster and shows all calls that have 15 mins left before the SLA runs out (a warning to prompt us):Select logged,(faultlog.id_prefix+faultlog.id) as jobid,response from faultlog left outer join notes ON faultlog.id=notes.id AND faultlog.id_prefix=notes.id_prefix INNER JOIN contact ON contact.id=faultlog.contid WHERE notes.date IS NULL AND faultlog.status<1 AND faultlog.description != '' AND response>0 AND DATEDIFF(Minute,DATEADD(Hour,response,logged),GetDate())>-15
Is it possible to modify this code so it does what the first code does (counts sla's met this week)....help plz