Retrieving Data Using Columns Names Stored In Reference Table

  • As a result of a data import the ffg table was created.

    Date Store A Store B Store C Store D Store E

    2009-01-31 100 150 300 400 500

    2009-02-28 300 170 200 550 489

    2009-03-31 210 200 260 530 420

    I need to insert the data into the ffg table

    Date

    StoreID

    Sales

    This is my reference table for the Store Ids

    StoreID StoreName

    1 Store A

    2 Store B

    3 Store C

    4 Store D

    5 Store E

    At some point more store will be added and as a result, the import data table will have an extra column matching the store name.

    I need a query that pulls out the data from the data import table using the store names from the Store Table.

    I need a query flexible enough that can cater for new store names without it being known.

  • See if this helps. Look for the UNPIVOT usage.

    http://technet.microsoft.com/en-us/library/ms177410.aspx

  • Thanks. 🙂 Exactly what I was looking for.

  • You're welcome...

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

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