重构 COALESCE 比较
Refactoring a COALESCE comparison
在 WHERE
子句的 OR
部分,我有这样的内容:
COALESCE(Table2.FireDate, Table1.HireDate,'06/06/2079') = ISNULL(Table3.DeathDate,'06/06/2079')
我想看看有没有办法避免 COALESCE
调用并仍然获得相同的结果?如果可能的话,我希望获得一些性能。
我不确定性能会更好。但是您可以根据需要摆脱合并:
declare @fireDate date = null -- '01/20/2017'
declare @hireDate date = '01/20/2017'
declare @deathDate date = '01/20/2017'
if (COALESCE(@fireDate, @hireDate, '06/06/2079') = ISNULL(@deathDate, '06/06/2079'))
begin
select '+'
end;
if(@fireDate is null and @hireDate is null and @deathDate is null)
or (@fireDate = @deathDate)
or (@fireDate is null and @hireDate = @deathDate) begin
select '+'
end;
在 WHERE
子句的 OR
部分,我有这样的内容:
COALESCE(Table2.FireDate, Table1.HireDate,'06/06/2079') = ISNULL(Table3.DeathDate,'06/06/2079')
我想看看有没有办法避免 COALESCE
调用并仍然获得相同的结果?如果可能的话,我希望获得一些性能。
我不确定性能会更好。但是您可以根据需要摆脱合并:
declare @fireDate date = null -- '01/20/2017'
declare @hireDate date = '01/20/2017'
declare @deathDate date = '01/20/2017'
if (COALESCE(@fireDate, @hireDate, '06/06/2079') = ISNULL(@deathDate, '06/06/2079'))
begin
select '+'
end;
if(@fireDate is null and @hireDate is null and @deathDate is null)
or (@fireDate = @deathDate)
or (@fireDate is null and @hireDate = @deathDate) begin
select '+'
end;