Better a query that takes tooooo long to run
Posted on 2011-09-08
I have the query below, is there a way to change the syntax and get the same results while making it faster ? It takes about 30-40 seconds to return results :( should take a second or two the most. Help is appreciated.
SELECT activities.activityid as id, b.firstnm + ' ' + b.lastnm + ' ' + '(' + processcatalog.processcatalog + ')' + ' ' + '-' + ' ' + activities.processtep as actdesc,activities.partylist as longdesc, activities.schdemailon as datestarted, activities.schdemailon as datefinished, activities.actnote as repeat,activities.actnote as apptype FROM dbo.Activities
Inner join cases on activities.caseid = cases.id Inner join atts on cases.id = atts.caseid INNER JOIN Users ON atts.userid = users.userid INNER JOIN Users as b On cases.alienid = b.userid INNER JOIN Processcatalog ON cases.Process = Processcatalog.ProcesscatalogID WHERE activities.FirmId = 71 and ActType ='HISTORY' and sent_by = 1 and atts.userid = 127273 and Schdemailon is not null
UNION ALL SELECT activities.activityid as id, activities.ActName as actdesc, activities.actdesc as longdesc,activities.dateinitiated as datestarted,activities.lastmodified as datefinished,activities.processtep as repeat,activities.Partylist as apptype
FROM ((dbo.Activities LEFT JOIN dbo.Cases ON dbo.Activities.CaseId = dbo.Cases.Id) ) LEFT JOIN dbo.Atts ON dbo.Atts.CaseId = dbo.Cases.Id INNER JOIN Users ON Activities.sent_by = Users.UserId
WHERE Activities.FirmId = 71 AND (Activities.ActType = 'Calendar') AND sent_by = 127273