Hello all,
I have a store procedure where i have one sub query to return no . of attendance between period selection
basically like this,
SELECT EmployeeCode,COUNT(DISTINCT ATTENDANCE_DATE)AS Mkt_AttendanceFROM [dbo].[View_Marketing_Person_Attendance]
WHERE CONVERT(DATE,ATTENDANCE_DATE) BETWEEN @from AND @to
GROUP BY EmployeeCode
@from and @to parameters passed to procedure and used in sub query to filter attendance of period of employees
and i have join that query to main table in procedure using a EmployeeCode and displaying
,SUM(DISTINCT Mkt_Attendance) AS Mkt_Attendance in Main select area
(using sum because having grouping summarize query )
Now , above query is run very fast as it use index seek on Attendance_date based in view defination of a log table and returns only 265 rows for period 2015-04-01 and 2015-06-30 in 0 sec. approx.
now when i am running a procedure for 2015-04-01 and 2015-06-30 it executes in 11 sec. after commenting a sub query
and when i removed a comment and executes it takes 32 sec. but a strange is in statistics it shows
Table 'Worktable'. Scan count 93, logical reads 6576643, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
worktable only shows when i use above sub query as it is because of the sub query i know.
please , help why the work table is showing high reads and is slowing query this much .
Dilip Patil..