C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

resolve this using pivot in sql 2005


Posted Date: 26 Aug 2008      Posted By: baranidharan      Member Level: Silver     Points: 1   Responses: 1



Hi i have table in below format and i want the outputs in below mentioned format...

ProductID BillDeterminatn Term ProductTerm Value
100 1 1 12 10
100 1 2 14 10
100 1 3 16 10
100 2 1 10 5
100 2 2 11 5
100 2 3 14 5
101 1 1 10 6
101 1 2 11 6
101 1 3 14 6
102 2 1 10 7
102 2 2 11 7
102 2 3 14 7
102 4 1 10 8
102 4 2 11 8
102 4 3 14 8


output should be in these format:

output;1

ProductID Term1 Term2 Term3
100 12 14 16
101 10 11 14
102 10 11 14

output:2
ProductID BillDeterminant Value
100 1 10
100 2 5
101 1 6
102 2 7
102 4 8



please give me possible solution to get the desired output...






Responses

Author: satishkumar    27 Aug 2008Member Level: BronzeRating: 4 out of 54 out of 54 out of 54 out of 5     Points: 6

To produce Output1:
SELECT productid,[1] AS term1,[2] AS tem2,[3] AS term3
FROM
(SELECT productid,[term],productterm FROM <table_name>)p
PIVOT
(max(productterm) FOR [term] IN ([1],[2],[3]))AS pvt

Hope this might help you

Thanks,
satish



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : mysql urgent
Previous : Stored Procedure..? - 1
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use