Click here to Skip to main content
12,396,047 members (65,506 online)
Rate this:
 
Please Sign up or sign in to vote.
Following are my tables

PartyMaster - PId PK Identity | PName varchar

ItemMaster - ItemId PK identity | ItemCode varchar unique | ItemName varchar

ItemVendorMaster - ItemVendorId PK Identity | ItemId FK(ItemMaster-ItemId) | PartyId FK(PartyMaster-PId) | Percent double


Now I want to show the above 'ItemVendorMaster' details in gridview asp.net as follows
ItemId | ItemCode | ItemName | Party1 | %1 | Party2 | %2 | Party3 | %3
1      | 1	 | PC	    | ddl(P1)|50  | ddl(P2)| 50 | ddl(NS)  |  
2      | 2	 | CPU	    | ddl(P2)|70  | ddl(P4)|20  |ddl(P8) |10
ddl - Drop Down List
NS - Not Selected(Blank)
But the data in table 'ItemVendorMaster' is like as follow
ItemVendorId | ItemId | PartyId | Percent
1	     | 1      | 1       | 50
2	     | 1      | 2       | 50
3	     | 2      | 2       | 70
4	     | 2      | 4       | 20
5	     | 2      | 8       | 10
How can I show above grid, I am not getting sql query for it, Please Help
Note:
In grid same row must not have same name selected from dropdown
Sum of all % in same row in grid must be 100%
Posted 6-May-13 19:34pm
Updated 6-May-13 19:36pm
v2
Comments
CHill60 7-May-13 10:02am
   
If you google for "pivot table in sql server" this might get you going (depends on which version of sql you're using)
amit Baswa 9-May-13 4:40am
   
I am using Sql Server 2005
amit Baswa 9-May-13 4:42am
   
can u please give solution here.??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 7 May 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100