Convert multiple columns into a single row in SQL

;WITH CTE

AS

  (

  SELECT * FROM (

  SELECT sub1 ,sub2 ,sub3 , sub4,sub5,sub6 FROM i1) T

  UNPIVOT ( Value FOR N IN (sub1 ,sub2 ,sub3 , sub4,sub5,sub6))P

  )

 SELECT Value AS i1

 FROM CTE

 

 

Here  sub1 ,sub2 ,sub3 , sub4,sub5,sub6 are column names of a table i1

 

UNPIVOT is used to convert column to row

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s