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)
 Urgent---Reverse table

Author  Topic 

NasimCZD
Starting Member

1 Post

Posted - 2009-02-24 : 13:45:13
hi guys,

I wrote a query that the results are in table A and I want to revese the results to table B....
Would you please help me how I can write another query or complete my query?
Thanks

Table A:
Name No.
A 1
B 2
C 3
D 4
Table B:

Name A B C D
No. 1 2 3 4


sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-02-24 : 13:46:34
Read PIVOT.
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-25 : 01:59:37
go through this link too
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/dynamic-crosstab-with-multiple-pivot-columns.aspx
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-02-25 : 02:10:59
using Dynamic CrossTab

select
sum(case when name = 'A' then no else 0 end) A,
sum(case when name = 'B' then no else 0 end) B,
sum(case when name = 'C' then no else 0 end) C,
sum(case when name = 'D' then no else 0 end) D
FROM @TEMP
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-02-25 : 02:11:28
Using Pivot

SELECT A,B,C,D
from @temp
pivot (SUM(no) for NAME in (A,B,C,D)) p
Go to Top of Page
   

- Advertisement -