I want to write a stored procedure that works something like this:
SELECT * from T where T.A = @a and T.B = @b
if it returns rows, return these rows; if not, return
SELECT * from T where T.A = @a and T.B IS NULL
Edit:
He believes that there should be a way to create such a procedure so that it executes the first request once and starts the second request only if necessary .
The end of editing.
The best I could do is to follow that (theoretically) execute the first request twice, if possibly caching it:
IF EXISTS (SELECT * from T where T.A = @a and T.B = @b) THEN
SELECT * from T where T.A = @a and T.B = @b
ELSE
SELECT * from T where T.A = @a and T.B IS NULL
What is it worth it in Microsoft SQL Server 2008
source
share