• Not much in the way of details to work with here. I took a shot in the dark. See if this gets you close.

    select * from

    (

    select ROW_NUMBER() over(partition by c.ClientID order by case when at.CODE = '004' then 1 else 0 end) as RowNum,

    CASE

    WHEN at.CODE = '004'

    THEN a.FName + ' ' + isnull(a.MName, '') + ' ' + + a.lname

    ELSE c.FName + ' ' + ISNULL(c.MName, '') + ' ' + c.LName

    END AS Tag_Data

    FROM Client AS C

    LEFT JOIN

    -- Note the order of the clausing here. It causes an

    -- inner join to the rest of the tables BEFORE the

    -- outer join is included.

    Client_To_Alias_Collection AS AC

    INNER JOIN Alias AS A

    ON AC.OID_Link = A.OID

    INNER JOIN Alias_Type AS AT

    ON AT.OID = A.Alias_Type_Moniker

    ON c.oid = ac.oid

    AND A.EXPDate IS NULL WHERE c.OID = '12345'

    ) x

    where x.RowNum = 1

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/