您好我正在使用 SQL Server 2008。在我的数据库中有一个名为MemberBusiness
. 我想从该表中获取数据。
这是我的存储过程
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
在MemberBusiness
表中有大约 16560352 条记录。上面的 SP 给了我 1300 条记录,执行大约需要 30 秒,这对我来说是不可接受的。我使用过索引,但仍然需要很长时间才能执行。怎样才能更快地做到这一点?谢谢。