我在继承的存储过程中的联接上有这个子句:
WHERE a.is_active = 1
AND b.due_date <= ISNULL(@due_date_limit, b.due_date)
我该如何重写它以删除 ISNULL,因为它会导致严重的性能问题?
最佳答案
在这种情况下,我将有一个 if 语句,检查 @due_date_limit
IF (@due_date_limit IS NULL)
BEGIN
...
WHERE a.is_active = 1 --not required to compare b.due_date <= b.due_date
END
ELSE
BEGIN
...
WHERE a.is_active = 1
AND b.due_date <= @due_date_limit
END
关于sql - T-SQL ISNULL() 优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1444781/