How to convert vertical data to horizontal in sql

Conversion of vertical data to horizontal in sql: Today I am going to show you how to convert vertical data to horizontal in ms sql. Here we have multiple ways by which we can convert vertical data to horizontal in sql. Here are some simple transformation of data from vertical to horizontal. 

Table structure


 display data vertically in sql
Insert Some data in table and select it

How to convert vertical data to horizontal in sql

Method1: to convert vertical data to horizontal in sql
Select * from PartsItem

Declare @ProductSKU varchar(MAX)='  '
select @ProductSKU= @ProductSKU+ ISNULL
(ProductSKU+', ' ' ') from PartsItem Select @ProductSKU as ProductSKUCode



 display data vertically in sql


Method2: to transformation of vertical data to horizontal in sql
It will show the record is in form of XML


Select ProductSKU + ' , '  from PartsItem for xml path ('  ')

How to convert vertical data to horizontal in sql





Previous
Next Post »