Change is constant - 变化时唯一的永恒

在有大量数据时 少用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

posted @ 2016-03-23 10:56  人海灬  阅读(802)  评论(0编辑  收藏  举报