Hi I am using SQL Server 2008. In my database there is one table called MemberBusiness
. I want to get data from that table .
This is my stored procedure
SELECT BrokerId ,
RankId ,
MemberId ,
InstallmentId ,
PlanId ,
IntroducerId ,
Date ,
SelfAmount ,
UnitAmount ,
SpotAmount ,
ORBPercentageSelf ,
ORBPercentageUnit ,
ORBAmountSelf ,
ORBAmountUnit ,
IsSelfBusiness ,
Mode ,
InstallmentNo ,
PlanType ,
PlanName ,
CompanyId ,
CscId ,
Year ,
CreateDate ,
ModifideDate
FROM dbo.MemberBusiness AS mb
WHERE ( @CscId = 0
OR mb.CscId = @CscId
)
AND ( @CompanyId = 0
OR CompanyId = @CompanyId
)
AND BrokerId IN ( SELECT bt.BrokerId
FROM #brokerTable AS bt )
AND mb.Date >= @StartDate
AND mb.Date <= @EndDate
AND mb.RankId >= @FromRankId
AND mb.RankId <= @ToRankId
In MemberBusiness
table there is approx 16560352 records. Above SP gives me 1300 records and takes approx 30 seconds to execute which is not acceptable for me. I have used Indexing but still its take long time to execute. How can do this faster?. Thanks.