Pivot "mergings" cells

  • Hi there,
    Is it possible to create a pivot table from more than one fields?

    [customer    sale_period    product_category    amount
    [sale_period] is a known value such as 3, 6, 9, 12/code]

    What I try to achieve is

    [[customer]    [sale_period3 + product_category1]    [sale_period3 + product_category1]    [amount]/code]

    So in other words, the pivot table would become quite 'wide' since every combination of the known contents of [sale_period] and [product_category] would become a column.

    Thanks for any help 🙂

  • Please post a create table script, inserts with sample data, what you've tried, any errors and expected output based on sample data provided.

  • Sure, you can read the following article to know the best way to do it.
    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - SQLServerCentral

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

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

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