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 2000 Forums
 Transact-SQL (2000)
 Transpose ?

Author  Topic 

tomino79
Starting Member

13 Posts

Posted - 2005-09-12 : 10:53:09
I typed this word to the search combo and foung nothing ;-)

I know in DB design is very wierd to transpose data but I need this:

Table Actions:
date action
1.1 Meeting
2.1 Holiday
3.1 Meeting
4.1 Sick day
1.2 Meeting
9.2 Meeting
3.3 Meeting

And I need result like this:

Meeting Holiday SickDay
5 1 1

It is possible only with cursors in stored procedure right? Or is it doable only with selects ?

Tomas.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-09-12 : 11:13:55
http://weblogs.sqlteam.com/jeffs/archive/2005/05/02/4842.aspx

Go with the flow & have fun! Else fight the flow
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2005-09-12 : 11:29:20
howzabout this?



create table Actions ([Date] int, [Action] varchar(10))

insert into Actions select 1,'Meeting'
insert into Actions select 1,'Holiday'
insert into Actions select 1,'Meeting'
insert into Actions select 1,'Sick day'
insert into Actions select 2,'Meeting'
insert into Actions select 2,'Meeting'
insert into Actions select 3,'Meeting'

select [action], count(date) as [# of Actions]
from Actions
group by [action]
order by [action]

drop table Actions


Help us help YOU!
Read this blog entry for more details: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

*need more coffee*
SELECT * FROM Users WHERE CLUE > 0
(0 row(s) affected)
Go to Top of Page
   

- Advertisement -