• Here you go, it generates the expected output based on your sample data.

    ;With MySampleData([Member],[primarycondition],[primaryintensity],[secondarycondition],[secondaryintensity])

    AS

    (

    SELECT 'M2345','hf','1','','' UNION ALL

    SELECT 'M2345','COPD','1','','' UNION ALL

    SELECT 'M2345','CAD','1','','' UNION ALL

    SELECT 'M2345','dia','1','','' UNION ALL

    SELECT 'M2345','Ast','1','','' UNION ALL

    SELECT 'M2345','hf','2','','' UNION ALL

    SELECT 'M2345','COPD','2','','' UNION ALL

    SELECT 'M2345','CAD','2','','' UNION ALL

    SELECT 'M2345','dia','2','','' UNION ALL

    SELECT 'M2345','Ast','2','',''

    )

    SELECT * FROM MySampleData

    By the way, I couldn't use your DDL because M2345 is not an int.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2