transpose rows to columns

  • Hi,

    i have a table like this:

    ID Priority Acct_no ICDCode

    1 1 123 1.0

    1 3 123 1.5

    1 4 123 2.0

    2 1 234 1.8

    2 2 234 1.5

    3 1 456 3.7

    3 3 456 4.1

    3 5 456 4.0

    3 7 456 3.3

    3 8 456 3.6

    i need to insert into a table like this:

    ID Acct_no P1 ICDCd1 P2 ICDCd2 P3 ICDCd3 P4 ICDCd4 P5 ICDCd5

    1 123 1 1.0 3 1.5 4 2.0

    2 234 1 1.8 2 1.8

    3 456 1 3.7 3 4.1 5 4.0 7 3.3 8 3.6

    there will always be max 5 priorities for each account. I think i can do this with a cursor (although i can't picture the syntax in my head). I wasn't sure if there was a set based way to do this to stay away from the cursor.

    Anyone have any ideas??

    thanks

    Scott

  • I can think of only one option (since you've posted in SQL2K forum it's prior 2K5, I assume):

    One of Jeff Modens great articles:

    http://qa.sqlservercentral.com/articles/T-SQL/63681/.

    If you have trouble applying it to your scenario come back and let us know where you got stuck and we'll help you out!



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

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