Click here to Skip to main content
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 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 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 CPallini 375
1 Sergey Alexandrovich Kryukov 370
2 BillWoodruff 314
3 George Jonsson 274
4 OriginalGriff 257
0 OriginalGriff 5,030
1 CPallini 4,115
2 Sergey Alexandrovich Kryukov 3,554
3 George Jonsson 2,826
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2014
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