Home Forums SQL Server 2008 T-SQL (SS2K8) how to return email id if it contains dell.com otherwise any one email in the group RE: how to return email id if it contains dell.com otherwise any one email in the group

  • 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