June 22, 2006 at 3:26 pm
Do you have any idea why the order of the conditions in the follow code would cause SqlServer's memory usage to rise from 20M to 200M ?
declare @UWI_Equals VARCHAR(13)
set @uwi_equals = '0014010606000'
SELECT *
FROM [Well]
WHERE
((UWI = @UWI_Equals) OR (@UWI_Equals Is Null) ) -- small memory usage: 20M
-- ((@UWI_Equals Is Null) OR (UWI = @UWI_Equals)) -- big memory usage: 200M+
ORDER BY UWI ASC
June 22, 2006 at 7:41 pm
Yes,
It "pukes" because you first compare a variable to null so it must first try to compare every record to a condition that does not exist.
Use the first form...
--Jeff Moden
Change is inevitable... Change for the better is not.
June 23, 2006 at 8:26 am
Snarky...=D Thanks!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply