Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have a query which returns data as below

select n.Key, np.value from Test1 np join Test2 n on n.Key = np.Key where n.NodeKey = 10000002 && np.pKey in (4,6,7,10,12)

which returns data as below

Key value
-------- ------
10000002 2
10000002 0
10000002 2
10000002 True
10000002 1

Test2 is look up Table as below

Key PKey Value
---------------------------------------
10000002 4 2
10000002 6 0
10000002 7 2
10000002 10 True
10000002 12 1


Wanted to change the query so that it should return data as below

NodeKey Value1 Value2 Value3 Value4 Value5
--------------------------------------------------
10000002 2 0 2 True 1

Can you please help me with this.

What I have tried:

Tried restructuring the query so that it returns data horizontally
Posted
Updated 24-Oct-18 21:48pm
Comments
jsc42 25-Oct-18 3:56am    
This is known as a Pivot Table. Google it - there are a lot of possible solutions for SQLServer as that does not support them out of the box. However, the solutions are not easy.

1 solution

 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900