Columns into Row - Help

  • Hello All,

    Looks like a lot of good help available on this site. I think I found a place to hang. Need some help. Not a TSQL guru. Yet.

    Here's my problem. I have this table. How do I do this? Or just point ot some reading and I'll get on with it. Thanks. BPH

    ClaimID Claim_LnRuleID

    20001535

    20001434

    20001242

    I would like to create a table that list the RuleID Horizontally

    ClaimIDClaim_lnRuleID1RuleID2RuleID3

    20001 535434242

    BPH

  • Does your table contain some kind of ID field ?

    If so you could try something like

    select

    claimID,

    claim_ln,

    case when ID = 1 then RuleID else NULL end as RuleID1

    case when ID = 2 then RuleID else NULL end as RuleID2

    case when ID = 3 then RuleID else NULL end as RuleID3

  • Hi BPH,

    several links on the pivoting (crosstab) subject:

    http://www.sqlservercentral.com/scripts/contributions/818.asp

    http://www.sqlservercentral.com/scripts/contributions/931.asp

    http://www.sqlservercentral.com/scripts/contributions/936.asp

    Also, you can search for "pivot" or "crosstab" in tha scripts library .

    Regards,

    Goce Smilevski.

  • Thanks to Junie01 and Goce Smilevksi. I will persue those avenues and try to figure this out. .

     

    BPH

  • If this is a conversion from te old situation to a new one (OLTP) create a table using a LOOP scanning you old DDL and rebuild the new table dynamicly. Afterwards you can use this same mechanism for populating your table as well.

    Just a thought....

    GKramer

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply