set @sumresult1 = (select count(pallets_L2Code) from TransHistory_Temptable where AssignmentNo_Var = @tempAssignmentNum and pallets_L2Code =11)
数据库里纪录条数是19000条, 我测试了,就这条语句占用了太多时间,有没有好的优化语句,实在想不出了. 用游标也是一样花时间
数据库里纪录条数是19000条, 我测试了,就这条语句占用了太多时间,有没有好的优化语句,实在想不出了. 用游标也是一样花时间
AssignmentNo_Var/pallets_L2Code检查有没有建索引,没有时建上
索引有没有?
select @sumresult1 = count(pallets_L2Code) from TransHistory_Temptable where AssignmentNo_Var = @tempAssignmentNum and pallets_L2Code =11
这样标准点,看看执行计划,是否用了索引?如果用到了,可能无法再优化了
(如果这样双条件的多,键个复合索引能快)
你的sql语句也不复杂,最好是对(AssignmentNo_Var,pallets_L2Code)建索引。