• rburko (9/17/2012)


    This should be easy but I'm not getting this to work.

    I have a number of rows that look something like this:

    reckey amt1 amt2amt3 amt4 amt5

    ABCD1234 44.92 14.422 0 11.52

    I'm trying to use the t-sql Unpiovt statement to create this:

    reckey amtnumber amt

    ABCD1234 1 44.92

    ABCD1234 2 14.4

    ABCD1234 3 22

    ABCD1234 4 0

    ABCD1234 5 11.52

    Can anyone provide an example of how to make this work?

    Other than starting with the link provided by Lynn I would advise you to normalize your data if at all possible. This type of structure is a PITA to work with.

    If you can post ddl, sample data and what you tried so far you will likely find a lot of help. Take a look at the first link in my signature for best practices when posting questions.

    _______________________________________________________________

    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/