How to?

  • Hello,

    I was wondering if anyone knows how to insert data from

    table A

    [Country],

    [State],

    [ID],

    [2008],

    [2009],

    [2010]

    schema into

    table B

    [Country],

    [State] ,

    [ID],

    [Year], -- being the column heading of 2008, 2009 or 2010

    [YearValue], -- the data contained in column for the respective year

    I'm a bit stuck on this one

    Cheers 🙂

    Remember
    Without Change something sleeps inside of us that seldom awakens, the sleeper must awaken!!

  • Investigate the UNPIVOT clause in Books Online.

  • [font="Verdana"]Have you had a look at the UNPIVOT command on SQL Server Books Online? I suspect that would do what you want.[/font]

  • Thanks for the heads up 🙂

    Remember
    Without Change something sleeps inside of us that seldom awakens, the sleeper must awaken!!

  • Mr J (2/19/2009)


    Hello,

    I was wondering if anyone knows how to insert data from

    table A

    [Country],

    [State],

    [ID],

    [2008],

    [2009],

    [2010]

    schema into

    table B

    [Country],

    [State] ,

    [ID],

    [Year], -- being the column heading of 2008, 2009 or 2010

    [YearValue], -- the data contained in column for the respective year

    I'm a bit stuck on this one

    Cheers 🙂

    insert into dbo.tableB

    select

    [Country],

    [State],

    [ID],

    2008,

    [2008]

    from

    dbo.tableA

    union all

    select

    [Country],

    [State],

    [ID],

    2009,

    [2009]

    from

    dbo.tableA

    union all

    select

    [Country],

    [State],

    [ID],

    2010,

    [2010]

    from

    dbo.tableA

  • Sweet very cool 😀

    Remember
    Without Change something sleeps inside of us that seldom awakens, the sleeper must awaken!!

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

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