I have created a stored procedure to get data. In this stored procedure, I have returned 1 table and table stores the data above 1 lakh + data. 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:
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, 
    ISNULL(uf.TotalCount, 0) 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,UF.InsertDateTime)) OVER (partition by datepart(MM,UF.InsertDateTime)) AS TotalCount
               FROM dbo.UserFollowers UF
               INNER JOIN dbo.Users U on U.UserId = UF.FollowerId
               WHERE DATEDIFF(mm,UF.InsertDateTime, DATEADD(mm, T.i, GETDATE())) = 0 and UF.IsFollowed = 1 
            ) uf
            order by DATEPART(MM,convert(datetime,FORMAT(dateadd(MM, T.i, getdate()),'MMMM') +'01 '+@year,110))
i am also try some other query for the improve speed of query but still i am getting same time. here this query also print.
declare @StartDate datetime = dateadd(year , datediff(year , 0, getdate() )  , 0)
declare @tempT2 table 
    (
        MNo int,
        [Month] datetime,
        NextMonth datetime)
 ;with Months as (
select top (12) 
 MNo = row_number() over (order by number)
 ,[Month] = dateadd(month, row_number() over (order by number) -1, @StartDate)
, NextMonth = dateadd(month, row_number() over (order by number), @StartDate)
 from master.dbo.spt_values
)
insert into @tempT2
select * from Months
select 
m.MNo
 , Month = format(m.Month, 'MMM-yy')
  , tally = count(UF.InsertDateTime)
   from @tempT2 m
 left join dbo.UserFollowers UF
 INNER JOIN dbo.Users U on U.UserId = UF.FollowerId
on UF.InsertDateTime >= m.Month
  and UF.InsertDateTime < m.NextMonth where  UF.IsFollowed = 1 
group by  m.MNo,format(m.Month, 'MMM-yy')
order by MNo
here this is my both query i have try but still i am not getting success for the improve the speed of the query. and sorry but i can not see here my execution plan of the query actually i have not permission for that.
 
     
    