Constant Scan doesn't work in MS SQL when I use variable

Viewed 38

I have a query that takes long time to complete and that I don't want to execute if some variable is false.

DECLARE @b = 0

SELECT *
FROM DummyTable
WHERE @b = 1

However, it still takes a lot of time to complete while I expect Constant Scan to be executed first:

enter image description here

My expectation is:

SELECT *
FROM DummyTable
WHERE 0 = 1

With execution plan:

enter image description here

0 Answers
Related