Subject [ib-support] Re: SQL ORDER BY problem
Author Svein Erling Tysvær
>What's wrong with this in a SELECT stored proc, or did I not follow your
logic?

Nice try Andrew, but you do not need any SP for this question.

>EXISTS is my favourite keyword :-)

Exactly, use it directly within the SQL:

SELECT * FROM TableA
WHERE C1 = 'X'
AND (C2 = 'Y' OR NOT EXISTS(SELECT 1 FROM TableA B WHERE B.C1 = 'X' AND
B.C2='Y'))

No reason to make simple things complicated (though if speed is a big issue,
your solution may be slightly faster since you only execute EXISTS once),
Set
-well beaten by Andrew in the slogan competition