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 2008 Forums
 Transact-SQL (2008)
 Pivot the table

Author  Topic 

baburk
Posting Yak Master

108 Posts

Posted - 2011-11-11 : 09:23:17
DECLARE @TempTable TABLE(Client VARCHAR(50), Project VARCHAR(50), Mode VARCHAR(20), KEYS VARCHAR(10), FV VARCHAR(10), VC VARCHAR(10), VE VARCHAR(10), VEC VARCHAR(10), VFC VARCHAR(10), TimeTaken INT)
INSERT INTO @TempTable
SELECT 'CodeProject','Windows','V3','0','0','0','0','0','0','1' UNION ALL
SELECT 'CodeProject','web','C0','383','357','0','0','0','0','61' UNION ALL
SELECT 'CodeProject','web','E0','1636','444','1298','0','0','0','750' UNION ALL
SELECT 'CodeProject','web','V0','1510','1272','49','1370','0','6','374' UNION ALL
SELECT 'CodeProject','web','V1','78','8','0','73','0','0','30'

SELECT * FROM @TempTable

From the above table the required resultant table to be like this

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-11-11 : 09:38:18
Here's a start. Might need outer joins and coalesce if not all rows are there.

select v3.Client, v3.Project, v3.keys, v3.FV, v3.ve, C0.keys, C0.FV, C0.ve
from (select * from @TempTable where Mode = 'v3') v3
join (select * from @TempTable where Mode = 'C0') C0
on v3.Client = c0.Client


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -