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.
Author |
Topic |
sridhar3004
Starting Member
34 Posts |
Posted - 2011-01-31 : 01:29:17
|
I've the following dataProductMasterP1P2P3CategoryMaster1 P1 c12 P1 c23 P2 c14 P2 c25 P3 c16 P3 c2TicketMasterID CategoryMaterID Status1 1 Open2 2 Closed3 3 PendingI want an output that gives me productwise, categorywise, count of statusesIn the example I mentioned above, the output will beProduct 1Category 1Open Closed Pending1 0 0Category 2Open Closed Pending1 0 0and so on......Any answers will be highly appreciated |
|
sathishmangunuri
Starting Member
32 Posts |
Posted - 2011-01-31 : 07:04:46
|
Hi,As per my understand i have written this.If my assumption is wrong can you clearly explain the scenario. i have question that what is categorymasterid in Ticketmaster table?see this and clarify?create table #ProductMaster(pid varchar(2))insert into #ProductMaster select 'P1' union allselect 'P2' union allselect 'P3' create table #CategoryMaster(id int,pid varchar(2),cid varchar(2))insert into #CategoryMasterselect 1,'P1','c1' union allselect 2,'P1','c2' union allselect 3,'P2','c1' union allselect 4,'P2','c2' union allselect 5,'P3','c1' union allselect 6,'P3','c2'create table #TicketMaster(ID int,CategoryMaterID varchar(2),Status varchar(10))insert into #TicketMasterselect 1,'c1','Open' union allselect 2,'c2','Closed' union allselect 3,'c3','Pending'select * from #TicketMasterselect pid,cid as category,(case when status='open' then 1 else 0 end )as [open], (case when status='closed' then 1 else 0 end )as closed, (case when status='pending' then 1 else 0 end )as pendingfrom #CategoryMaster cjoin #TicketMaster t on c.cid=t.CategoryMaterIDsathish |
 |
|
|
|
|
|
|