Another PIVOT or Transpose Question

  • I have done some research on this and come up with nada. Given this table:

    LastName Qty

    -------------------

    Smith 25

    Jones 19

    Baker 4

    Ford 11

    Etc....

    I would like to transpose this as follows:

    Smith Jones Baker Ford ...etc.

    ------------------------------------------

    25 19 4 11 ...etc.

    (Sorry about all that extra space, I am formattingly challenged today)

    The number of items is dynamic and could be upwards of 100. Seems to me this should be straightforward and simple- there are no necessary aggregations, no other formulas etc. Just rotate it, right?

    Every piece of code I have found (incl. BOL) involves 1) aggregate functions and 2) a fixed number of data items. Some of the older code (prior to having PIVOT available) is pretty complex. I can't help but wonder if there is a simple, elegant solution for this. :unsure:

  • Check out Dynamic Pivot both on this site and generally.

    Here are some sample articles:

    http://www.sqlservercentral.com/articles/Advanced+Querying/pivottableformicrosoftsqlserver/2434/

    http://weblogs.sqlteam.com/jeffs/archive/2005/05/02/4842.aspx

    It may take more than a few minutes to understand this rich topic

    Francis

  • That is one I did not find.. .thanks for the link!

    Although I was still hoping to find something simpler, this is working for us at the moment.

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

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