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 |
ajmaly
Starting Member
11 Posts |
Posted - 2010-07-26 : 06:44:20
|
I have a below output from a query, SELECT T.AS_Transaction_Key, MAN.AS_Metadata_Attribute_Name, TV.AS_Trans_Values_ValueFROM AS_Metadata_Attributes MANINNER JOIN AS_Transaction_values TV ON TV.AS_Trans_Values_AS_MetadataAttributes_Key = MAN.AS_Metadata_Attributes_KeyINNER JOIN AS_TRANSACTION T ON T.AS_Transaction_Key = TV.AS_Trans_Values_AS_Transaction_KeyAS_Transaction_Key AS_Metadata_Attribute_Name AS_Trans_Values_Value1 Transaction WF_TS1 Submitted 2/6/20101 By pdi/vmuser31 RefNo 341 TotalHours 152 Transaction WF_TS2 Submitted 2/6/20102 By pdi/vmuser32 RefNo 342 TotalHours 20Now, I need output like below,Txn_Key Transaction Submitted By RefNo TotalHours1 WF_TS 2/6/2010 pdi/vmuser3 34 152 WF_TS 2/6/2010 pdi/vmuser3 34 20How can I achieve this by using PIVOT/other trick? Any help is appreciated.ajmal |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-07-26 : 08:17:34
|
[code]; with resultas( SELECT T.AS_Transaction_Key, MAN.AS_Metadata_Attribute_Name, TV.AS_Trans_Values_Value FROM AS_Metadata_Attributes MAN INNER JOIN AS_Transaction_values TV ON TV.AS_Trans_Values_AS_MetadataAttributes_Key = MAN.AS_Metadata_Attributes_Key INNER JOIN AS_TRANSACTION T ON T.AS_Transaction_Key = TV.AS_Trans_Values_AS_Transaction_Key)select *from result r pivot ( max(AS_Trans_Values_Value) for AS_Metadata_Attribute_Name in ([Transaction], [Submitted], [By], [RefNo], [TotalHours]) ) p[/code] KH[spoiler]Time is always against us[/spoiler] |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|
|