Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mustbemikey
Starting Member
1 Post |
Posted - 2008-10-07 : 13:09:09
|
| Greatings Everyone, I posted a question about getting pivot table like results from sql server 2000. We have upgraded to sql server 2005 and I would really like to know how to use the pivot table functionality. I have seen other pivot table examples but I don't know how to use them for my needs and using my tables. What I want to do is have the result look like this: (The results are based on a category, the result below is given the category of wireless) Result (bellow) Wireless:Part Number | Description | Manufacturer | Price | FCC Certified | Frequency | Protocol1 | Part1 | Sony | 1.00 | [blank] |900-930 | DTS3 | Part3 | LG | 5.16 | N | [blank] | FHSS Here are the two table that I would have to pull data from: Table 1: Items_PublishedTable 2: Menu_Selected Items_Published:Part_Number | Description | Manufacturer | Price 1 | Part1 | Sony | 1.00 2 | Part2 | Sony | 3.14 3 | Part3 | LG | 5.16 4 | Part4 | LG | 3.02 5 | Part5 | Sony | 0.56 Menu_Selected:Category | Spec | Manufacturer | SpecValue | Part_Number Wireless | Frequency | Sony | 900-930 | 1Wireless | Protocol | Sony | DTS | 1 MCU | FCC Certified | LG | Y | 2Wireless | FCC Certified | LG | N | 3Wireless | Protocol | LG | FHSS | 3 Thank you for your responses. Always helpful! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-07 : 13:28:53
|
| [code]SELECT *FROM(SELECT p.Part_Number p.Description,p.Manufacturer,p.Price,m.Spec,m.SpecValue FROM Items_Published pINNER JOIN Menu_Selected mON m.Part_Number =p.Part_NumberWHERE m.Category='Wireless') tPIVOT (MAX(SpecValue) FOR Spec IN ([FCC Certified],[Frequency],[Protocol]))tmp[/code] |
 |
|
|
|
|
|