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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 View one column output into two Column

Author  Topic 

khanewal
Starting Member

33 Posts

Posted - 2010-09-07 : 00:29:25
HI Friends,

I have this data

DocID object
1 A
1 A
2 H
3 A
1 H

Required output

ID C1A C2H Total
1 3 1 4
2 0 1 1
3 1 0 1

Total C1A =4 C2H = 2 C1A+c2h = 6

can you please tell me how I can produce this kind of output in SQL

Heap Thanks,

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-09-07 : 02:14:25
[code]select *
from data
pivot
(
count(object)
for object in ([A], [H])
)p[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khanewal
Starting Member

33 Posts

Posted - 2010-09-07 : 02:23:28
Thanks, I have already done, but not sure how to total A, and H ?????????
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-09-07 : 02:27:41
[A] + [H] as Total


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khanewal
Starting Member

33 Posts

Posted - 2010-09-07 : 02:56:47
Thanks Khtan, its done
Go to Top of Page
   

- Advertisement -