读书人

请各位帮忙优化一下这个查询语句,该怎

发布时间: 2012-03-29 12:53:13 作者: rapoo

请各位帮忙优化一下这个查询语句
请各位帮忙优化一下这个代码,当BandingUnits为空时需要执行两遍查询,数据量多时会很慢,不知如何改进呀
select
isnull((Select
BandingUnits
From
dbo.MstProductUnits pu
Where
pu.ProductCode = fw.ProductCode
and pu.WarehouseCode = fw.WarehouseCode

),(Select
BandingUnits
From
dbo.MstProductUnits pu
Where
pu.ProductCode = fw.ProductCode
and pu.WarehouseCode = 0
)) as BandingUnits
from dbo.WrkForwarding as fw


[解决办法]
先分表,建立临时表,分块查找,范围缩小

读书人网 >SQL Server

热点推荐