WITH CTE AS (
SELECT acctno , email_id,
ROW_NUMBER() OVER(PARTITION BY acctno ORDER BY CASE WHEN email_id LIKE '%dell.com%' THEN 0 ELSE 1 END, email_id) AS rn
FROM #onner)
SELECT acctno , email_id
FROM CTE
WHERE rn=1
ORDER BY acctno;
____________________________________________________
Deja View - The strange feeling that somewhere, sometime you've optimised this query before
How to get the best help on a forum
http://www.sqlservercentral.com/articles/Best+Practices/61537