0
votes

1st Problem

I have a table

CatID   Category    IsArchived  
1       Category1   0  
3       category2   0  
4       Category3   0  
5       Category4   0  
6       Category5   0  
7       Category6   0  
8       Category7   0  

I want to convert rows to columns so that I have all categories in one row with column for each category.

Also, I want to bind this data to the Header column of a Gridview

2nd Problem

I have another table:

CCtID  ClientID CatID  CatStatus Date                  modifiedby  
1      1        1      1         2013-06-03 22:19:00   1  
2      1        3      1         2013-06-03 22:20:00   1  
3      1        4      0         2013-06-03 22:20:00   1  
4      1        5      0         2013-06-03 22:20:00   1  
5      1        6      1         2013-06-03 22:20:00   1  
6      1        7      1         2013-06-03 22:20:00   1  
7      1        8      0         2013-06-03 22:20:00   1  
8      2        8      0         2013-06-03 22:21:00   1  
9      2        7      0         2013-06-03 22:21:00   1  
10     2        6      0         2013-06-03 22:21:00   1  
11     2        5      1         2013-06-03 22:21:00   1  
12     2        4      1         2013-06-03 22:21:00   1  
13     2        3      0         2013-06-03 22:21:00   1  
14     2        1      0         2013-06-03 22:22:00   1  

I want to display categories and their status for each client in column format:

clientName  cat1  cat2  cat3  cat4  cat5  cat6  
1           1     0     1     o     1     1
1

1 Answers

0
votes

Assuming you are working with MS SQL server you need to use the PIVOT keyword. Link for the same: PIVOT AND UNPIVOT