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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 generic mapping

Author  Topic 

ajmaly
Starting Member

11 Posts

Posted - 2010-08-02 : 13:03:53
Below is the different output from a same query,

SELECT ASTV. Transaction_Key, ASMA. Attribute_Name, ASTV.Trans_Values
FROM
As_Transaction_Values ASTV
INNER JOIN AS_Metadata_Attributes ASMA ON ASMA.AS_Metadata_Attributes_Key = ASTV.AS_Trans_Values_AS_MetadataAttributes_Key


Output 1,

Transaction_Key Attribute_Name Trans_Values

15 Region_ID 34
15 WF_Position Clerk

Output 2,

Transaction_Key Attribute_Name Trans_Values
34 Total_Hrs 40
34 Overtime_Hrs 15
34 Emp_ID 012

Now, I want to convert by both outputs as below,

Concern is….the above query can generate any number of rows as above and Attribute_Name can also different for each output…. PIVOT is one of the option..but need some generic style…please suggest….

Output 1,

UID Region_ID WF_Position
15 34 Clerk


Output 2,

UID Total_Hrs Overtime_Hrs Emp_ID
34 40 15 012




ajmal

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-08-02 : 13:06:32
I can't get you, sorry.
How can a select give Output 1 and Output 2?
A query always gives ONE resultset.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-03 : 02:01:59
i think OP is asking for dynamic pivot. see below

http://sqlblogcasts.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -