Transform rows into columns in sql server

Published: 04 October 2020
on channel: ASP.NET With SQL SERVER
98
0

Using PIVOT operator we can very easily transform rows to columns.
Select Country, City1, City2, City3
From
(
Select Country, City,
'City'+
cast(row_number() over(partition by Country order by Country)
as varchar(10)) ColumnSequence
from Countries
) Temp
pivot
(
max(City)
for ColumnSequence in (City1, City2, City3)
) Piv


On this page of the site you can watch the video online Transform rows into columns in sql server with a duration of hours minute second in good quality, which was uploaded by the user ASP.NET With SQL SERVER 04 October 2020, share the link with friends and acquaintances, this video has already been watched 98 times on youtube and it was liked by 0 viewers. Enjoy your viewing!