Click here to Skip to main content
12,298,267 members (54,360 online)
Rate this:
 
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 10: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 18-Feb-13 17:52pm
   
That should be enough to understand this matter, a 5.
—SA
Hasham Ahmad 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2016
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