Click here to Skip to main content
11,484,162 members (69,029 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL Server
i want to implement the following scenario

change the following dataset
v1 1
v2 2
v3 3

to

v1 v2 v3
1 2 3


please help, i heard there is some pivot table thing, please share if there is any tutorial
Posted 18-Feb-13 11:34am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

if you just need the tutorial to implement SQL Pivot then

click here[^]
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 18-Feb-13 17:52pm
   
That should be enough to understand this matter, a 5.
—SA
Hasham Ahmad at 18-Feb-13 18:10pm
   
thanks Sergey :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi Friend,

Please find the below answer for your query.


CREATE TABLE #pvt 
(
na varchar(5),
id int
)
INSERT INTO #pvt (na,id) VALUES('v1',1),('v2',2),('v3',3)
 
SELECT * FROM #pvt 
 
SELECT v1 AS [V1],v2 AS [V2],v3 AS [V3] FROM
(
SELECT na,id  FROM #pvt 
)p
pivot 
(
min(id)
FOR na in (v1,v2,v3)
)as pvt
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 185
1 Frankie-C 155
2 Raje_ 155
3 OriginalGriff 147
4 CPallini 110
0 Sergey Alexandrovich Kryukov 8,484
1 OriginalGriff 7,948
2 Sascha Lefèvre 3,189
3 Maciej Los 2,601
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100