• Below is some DDL and a solution:

    --DDL

    USE tempdb

    IF OBJECT_ID('tempdb..Entries') IS NOT NULL DROP TABLE Entries;

    CREATE TABLE Entries (MSKEY int, ATTRNAME varchar(20), AVALUE varchar(20), primary key (MSKEY, ATTRNAME));

    INSERT Entries (MSKEY, ATTRNAME, AVALUE)

    SELECT 1234, 'NUMBER', '3' UNION ALL

    SELECT 1234, 'FNAME', 'DAVID' UNION ALL

    SELECT 1234, 'MNAME', 'M' UNION ALL

    SELECT 1234, 'LNAME', 'HUDSON' UNION ALL

    SELECT 2345, 'NUMBER', '5' UNION ALL

    SELECT 2345, 'FNAME', 'MARK' UNION ALL

    SELECT 2345, 'LNAME', 'WOOD' UNION ALL

    SELECT 2345, 'EMAIL', 'mwood@email.com';

    --OUTPUT

    SELECT DISTINCT

    e.MSKEY AS NUMBER,

    ISNULL(fn.AVALUE,'') AS FNAME,

    ISNULL(mn.AVALUE,'') AS MNAME,

    ISNULL(ln.AVALUE,'') AS LNAME,

    ISNULL(em.AVALUE,'') AS EMAIL

    FROM Entries e

    LEFT JOIN Entries fn

    ON e.MSKEY=fn.MSKEY AND fn.ATTRNAME='FNAME'

    LEFT JOIN Entries mn

    ON e.MSKEY=mn.MSKEY AND mn.ATTRNAME='MNAME'

    LEFT JOIN Entries ln

    ON e.MSKEY=ln.MSKEY AND ln.ATTRNAME='LNAME'

    LEFT JOIN Entries em

    ON e.MSKEY=em.MSKEY AND em.ATTRNAME='EMAIL'

    The solution I provided is not optimal - it uses a very expensive DISTINCT. I'm going to try to put together a faster query (unless someone beats me to it) . This will, however, get you the results you need.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001