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)
 Convert row into column

Author  Topic 

Marioluccio2001
Starting Member

2 Posts

Posted - 2010-04-20 : 11:38:49
Hi guys,

I have spent much time in converting row to column . This is an example

Time A1 A2 A3 A4 A5 A6 A7
09:30 0 0 0 1 0 0 0
10:00 0 0 0 1 0 0 0
10:30 0 0 0 0 0 0 1
11:00 0 0 1 0 0 1 0
09:00 1 0 0 0 1 0 0

I want to obtain this result:

Time1 Time2 Time3 Time4 Time5
09:30 10:00 10:30 11:00 09:00
0 0 0 0 1
0 0 0 0 0
0 0 0 1 0
1 1 0 0 0
0 0 0 0 1
0 0 0 1 0
0 0 1 0 0

Can anyone help me?

Thanks.

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-04-20 : 11:49:53
Have a look to below link.


http://beyondrelational.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx
Go to Top of Page

Marioluccio2001
Starting Member

2 Posts

Posted - 2010-04-22 : 03:08:29
Thanks for reply.
I read the article but I still solved using a pair of supporting tables.

Greetings
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-22 : 04:53:10
why? isnt method in link easier than using two additional tableS?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -