From: Plamen Ratchev on
SELECT TOP 1 WITH TIES source, price, state
FROM #TempTable
WHERE source IN ('Tiger', 'Ape', 'Elephant')
ORDER BY CASE source
WHEN 'Tiger' THEN 1
WHEN 'Ape' THEN 2
WHEN 'Elephant' THEN 3
END;

--
Plamen Ratchev
http://www.SQLStudio.com
From: SQL Learner on
Plamen,

This is cool. Thanks.

Could you or anyone explain how the following code work?

ORDER BY CASE source
WHEN 'Tiger' THEN 1
WHEN 'Ape' THEN 2
WHEN 'Elephant' THEN 3
END;

Thanks again.

Anthony

From: Plamen Ratchev on
The CASE expression does mapping of the sources to sort values, in a way giving priority to 1, then 2, 3, etc. That way
the source with sort value 1 (Tiger) is on top of the list if any entries exist. If not then the next one.

--
Plamen Ratchev
http://www.SQLStudio.com
From: SQL Learner on
Thanks again,Plamen!

SQL Learner