• Please in the future post ddl and sample data in a consumable format. Look at this as an example.

    if OBJECT_ID('tempdb..#Something') is not null

    drop table #Something

    create table #Something

    (

    Account int,

    MyDate date,

    Amt numeric(9,2)

    )

    set dateformat ymd

    insert #Something

    select 1111, '20090228', 200.00 union all

    select 1111, '20090328', 175.00 union all

    select 1111, '20090428', 250.00 union all

    select 1111, '20090528', 210.00 union all

    select 2222, '20120115', 100.00 union all

    select 2222, '20120213', 150.00 union all

    select 3333, '20110605', 300.00 union all

    select 3333, '20110705', 300.00 union all

    select 3333, '20110805', 300.00;

    OK so no we have something to work with. I then have a question for you. Is there a defined max amount of columns in your data or does this need to be dynamic?

    Since your data had a max of 4 sets per account I put together a query that will retrieve up to 4 groups.

    with MyData as

    (

    select Account, MyDate, Amt, ROW_NUMBER() over (partition by Account order by MyDate) as RowNum

    from #Something

    )

    select Account,

    MAX(case when RowNum = 1 then MyDate end) as Date1,

    MAX(case when RowNum = 1 then Amt end) as Amount1,

    MAX(case when RowNum = 2 then MyDate end) as Date2,

    MAX(case when RowNum = 2 then Amt end) as Amount2,

    MAX(case when RowNum = 3 then MyDate end) as Date3,

    MAX(case when RowNum = 3 then Amt end) as Amount3,

    MAX(case when RowNum = 4 then MyDate end) as Date4,

    MAX(case when RowNum = 4 then Amt end) as Amount4

    from MyData

    group by Account

    If this needs to be dynamic we can do that too. I just didn't want to put forth the effort helping with that unless it is needed.

    _______________________________________________________________

    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/