Använd en tabellvariabel:
create procedure xxxSearch @a nvarchar(80), @b nvarchar(80)...
as
begin
DECLARE @res TABLE(...)
INSERT INTO @res(...)
select whatever
from MyTable t
where ((@a is null and t.a is null) or (@a = t.a)) and
((@b is null and t.b is null) or (@b = t.b))...
if @@ROWCOUNT = 0
begin
INSERT INTO @res(...)
select whatever
from MyTable t
where ((@a is null) or (@a = t.a)) and
((@b is null) or (@b = t.b))...
if @@ROWCOUNT = 0
begin
...
end
end
SELECT ... FROM @res
end