Solved

Pivot/Unpivot

Posted on 2010-11-25
2
475 Views
Last Modified: 2012-05-10
What I want can be easily done with Pivot/Unpivot (one of those, I can never figure out which does which). I have a table where I have two relevant fields: CompanyNo and ItemNo. There are more, but I'm doing a distinct query. What I would like is to create an output table with each CompanyNo as row headers and ItemNo as column headers, with an X when there is one.

For example:

               Item1    Item2    Item3
Comp1       X                       X
Comp2       X          X
Comp3       X          X           X
Comp4                   X
0
Comment
Question by:Cluskitt
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 34212783
this is a dynamic pivot request...

see this article, for example, how to implement:
http://www.simple-talk.com/community/blogs/andras/archive/2007/09/14/37265.aspx
0
 
LVL 18

Author Closing Comment

by:Cluskitt
ID: 34228931
I'm sorry for not replying sooner. Been a busy week. Also, I'm having a hard time understanding that article, mostly because I have yet to understand pivot/unpivot correctly. However, I do not doubt that your answer is the correct one, so I'm awarding you with the solution and I'll try to study it better later.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now