I have one query for the report.
Use RIS select CİHAZ,sum(sayi) as [Çekim Sayısı], count(*) as [Hasta Sayısı] from (select CİHAZ,[KABUL NO],[TC NO], count(*) as Sayi from (SELECT a.GeneralReceptionNo as [KABUL NO], pa.TRIDNO as [TC NO], m.EtiketAdi as [CİHAZ] FROM Appointments a INNER JOIN Examinations e ON a.ObjectID=e.AppointmentID --aobject 1392334 INNER JOIN Patients pa ON a.PatientID=pa.ObjectID INNER JOIN Procedures pr ON a.ProcedureID=pr.ObjectID LEFT OUTER JOIN Machines m ON a.MachineID=m.ObjectID LEFT OUTER JOIN ExaminationReportAssistanceAssociation ra ON e.ObjectID =ra.ExaminationID INNER JOIN Hospital..Receptions r ON r.GeneralReceptionNo =a.GeneralReceptionNo WHERE CONVERT (DATE,e.CompletedDate)>='2018-12-01' AND CONVERT (DATE,e.CompletedDate)<'2019-12-30' AND e.IsCompleted =1) sorgu GROUP BY CİHAZ,[KABUL NO],[TC NO] ) sorgu2 GROUP BY CİHAZ ORDER BY CİHAZ
My problem is ,when i wrote condition is
AND CONVERT (DATE,e.CompletedDate)<'2019-11-30' , query not ended in 50 min but
if i wrote condition is
AND CONVERT (DATE,e.CompletedDate)<'2019-11-30'
I can get the result in 12 sec.
First example time range wider than the second example. I can't find a solution. Thanks for the help.