在有大量数据时 少用In(数据会丢失) 用left join 代替

select @From,
@To,
EffectiveDate,
GETDATE(),
Rate
from Config_Currency_ExchangeRate_Temp
where EffectiveDate not in (
select EffectiveDate
from Config_Currency_ExchangeRate
where EffectiveDate >=@BeginTime and
EffectiveDate <=@EndTime and
CIDFrom = @From and
CIDTo = @To
)
and EffectiveDate >=@BeginTime
and EffectiveDate <=@EndTime
and CIDFrom = @From
and CIDTo = @To
---------------------------------------------
---------------------------------------------
这种写法可以改为
select @From,
@To,
t.EffectiveDate,
GETDATE(),
t.Rate
from Config_Currency_ExchangeRate_Temp as t left join Config_Currency_ExchangeRate as r on t.EffectiveDate = r.EffectiveDate and t.CIDFrom = r.CIDFrom and t.CIDTo = r.CIDTo
where r.ID is null
and EffectiveDate >=@BeginTime
and EffectiveDate <=@EndTime
and CIDFrom = @From
and CIDTo = @To

原文地址:https://www.cnblogs.com/dwuge/p/5310142.html