I have created a stored procedure to get data. In this stored procedure, I have returned above 5+ table and table store the data above 20k+. So right now I have run the stored procedure that time I get the data in above 1 minute time take. I want just with in 1 second get data. I have set also SET NOCOUNT ON;
and also create missing index. Still I am getting same time for the get data.
This is my query =>
SET NOCOUNT ON;
DECLARE @CurMon int
DECLARE @year nvarchar(max)
SELECT @CurMon = month(getdate())
SELECT @year = year(getdate())
SELECT
FORMAT(dateadd(MM, T.i, getdate()), 'MMM-yy') AS DateColumn,
CASE
WHEN uf.TotalCount IS NULL
THEN 0
ELSE uf.TotalCount
END AS TotalCount
FROM
(VALUES (12-@CurMon),(11-@CurMon),(10-@CurMon),(9-@CurMon),(8-@CurMon),(7-@CurMon),(6-@CurMon), (5-@CurMon), (4-@CurMon), (3-@CurMon), (2-@CurMon), (1-@CurMon)) AS T(i)
OUTER APPLY
(SELECT DISTINCT
COUNT(datepart(MM, InsertDateTime)) OVER (PARTITION BY datepart(MM, InsertDateTime)) AS TotalCount
FROM
User
WHERE
DATEDIFF(mm, UF.InsertDateTime, DATEADD(mm, T.i, GETDATE())) = 0
AND IsLogin = 1) uf
ORDER BY
DATEPART(MM, CONVERT(DATETIME, FORMAT(dateadd(MM, T.i, GETDATE()), 'MMMM') + '01 ' + @year, 110))
I have like this query like this here please let me how can improve the this sp.