I have a table strcuture (golf score card) as follow:
HoleID int
CourseID int
Par INT
Distance INT
LowIndex INT
HighIndex INT
Sequence INT (representing the sequence of the hole: 1, 2, 3, ... 18)
This course has 18 holes.
I want to pivoting into:
Hole, 1, 2, 3, ... 18
Par, X, X, X, ... X
Distance, Y, Y, Y, ... Y
LowIndex, Z, Z, Z, ... Z
HighIndex, A, A, A, ... A
I can achieve this by using cursor but is there any better way?
TSQL has direct support for pivoting. Take a look here and here, for example.