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