mojtaba esmaeili
mojtaba esmaeili

Reputation: 1

How to rotate column to row?

How can I insert a column of table to row of another?

Example :

Value
------             
66
249
64
236

Rotate to this :

Digit1  Digit2  Digit3  Digit4
------------------------------
66      249     64      236

Upvotes: 0

Views: 765

Answers (2)

mojtaba esmaeili
mojtaba esmaeili

Reputation: 1

Look at this:

DECLARE @tblRangeIP TABLE(Digit1 INT,Digit2 INT,Digit3 INT,Digit4 INT)

SELECT * FROM dbo.f_Eng_Str_SplitOneDim('66.249.64.236','.')

select Digit1,  Digit2,  Digit3,  Digit4
from 
(
  SELECT Value FROM dbo.f_Eng_Str_SplitOneDim('66.249.64.236','.')
) d
pivot
(
  max(value)
  for d.Value in ( Digit1,  Digit2,  Digit3,  Digit4 )
) piv;

Upvotes: 0

Mukesh Kalgude
Mukesh Kalgude

Reputation: 4844

here are several ways that you can transform data from multiple rows into columns. In SQL Server you can use the PIVOT function to transform the data from rows to columns:

select Digit1,  Digit2,  Digit3,  Digit4
from
(
  select value
  from yourtable
) d
pivot
(
  max(value)
  for columnname in (Digit1,  Digit2,  Digit3,  Digit4)
) piv;

Upvotes: 2

Related Questions