I am doing a matching between two types of items say X and Y. And at some point the user would like to change the view, Then I have to make Rows as Cols and Cols as Rows.
Is it possible I can change this (example) table, Here 1 shows a matching exist between X and Y.
Matching | X1 | X2 | X3
------- ------ ----- ------
Y1 | 1 | 0 | 0
------ ------ ------ -----
Y2 | 0 | 0 | 1
------ ----- ------ ------
Y3 | 1 | 1 | 1
To This:
Matching | Y1 | Y2 | Y3
------- ------ ----- ------
X1 | 1 | 0 | 1
------ ------ ------ -----
X2 | 0 | 0 | 1
------ ----- ------ ------
X3 | 0 | 1 | 1
I have tried with Pivot but every thing is messed up :( . I don't know what to put in Max().
Here is what I tried so far:
SELECT [Matching]
,[X1]
,[X2]
,[X3]
FROM [Test].[dbo].[Matching_Full]
Select [Y1] as Y1,
[Y2] as Y2,
[Y3] as Y3
FROM
( Select [Matching]
,[X1]
,[X2]
,[X3]
FROM [Test].[dbo].[Matching_Full] ) PivotData
PIVOT
(
MAx (Matching)
FOR Matching IN
([Y1],[Y2],[Y3])
) AS Pivoting