请各位帮忙优化一下这个查询语句
请各位帮忙优化一下这个代码,当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
------解决方案--------------------先分表,建立临时表,分块查找,范围缩小