Click here to Skip to main content
Rate this: bad
good
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 20:34pm
Edited 6-May-13 20:36pm
v2
Comments
CHill60 at 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 at 9-May-13 4:40am
   
I am using Sql Server 2005
amit Baswa at 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
0 Sergey Alexandrovich Kryukov 269
1 OriginalGriff 240
2 CPallini 195
3 Maciej Los 177
4 BillWoodruff 173
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 7 May 2013
Copyright © CodeProject, 1999-2014
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