MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 25th, 2012, 04:32 PM
dmebeg dmebeg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 1 dmebeg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 17 sec
Reputation Power: 0
Pivot table??

I'm trying to create a view and think pivot command is what I need, but can't get it to do what I need. Here's what I have for data:

Serial_Num Machine Value0 Value1 Value2
XYZ123 1 1230100 1230101 1230102
XYZ123 2 1230200 1230201 1230202
XYZ123 3 1230300 1230301 1230302
XYZ124 1 1240100 1240101 1240102
XYZ124 2 1240200 1240201 1240202
XYZ124 3 1240300 1240301 1240302

Here is what I want for an output:


Serial_Num Mach1_Value0 Mach1_Value1 Mach1_Value2 Mach2_Value0 Mach2_Value1 Mach2_Value2 Mach3_Value0 Mach3_Value1 Mach3_Value2
XYZ123 1230100 1230101 1230102 1230200 1230201 1230202 1230300 1230301 1230302
XYZ124 1240100 1240101 1240102 1240200 1240201 1240202 1240300 1240301 1240302

I hope this makes sense, I've colour coded the data in an attempt to help explain.

Below is the closest I can get, but this query does not do what I want it to.

SELECT SERIAL_NUM,
[1] AS MC1,
[2] AS MC2,
[3] AS MC3
FROM
(SELECT SERIAL_NUM,
MACHINE,
VALUE00,
VALUE01,
VALUE02
FROM dbo.QA_DATA) AS SourceTable

PIVOT (
AVG(VALUE00)
FOR MACHINE IN (
[1],
[2],
[3]
)
) AS PIVIOTTABLE;

Thanks in advance

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Pivot table??

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap