Namaskar(Hi),
You can try this
1)create table emp(FirstName)
2)insert the values in that suppose i have 7 values
Sandeep
Prasad
Sharad
Sachin
Ravi
Ashish
Mangesh
and now i want to split my FistName column into 4 columns then
3);WITH T
AS (SELECT firstname,
( ROW_NUMBER() OVER (ORDER BY (SELECT 0)) - 1 ) / 4 AS Row,
( ROW_NUMBER() OVER (ORDER BY (SELECT 0)) - 1 ) % 4 AS Col
FROM tempemp)
SELECT [0] AS Column1,
[1] AS Column2,
[2] AS Column3,
[3] AS Column4
FROM T PIVOT (MAX(firstname) FOR Col IN ([0], [1], [2], [3])) P
ORDER BY Row
!!!!!!!!!!!!!!!!OUTPUT WILL BE!!!!!!!!!!!!!!!!!!
Column1 Column2 Column3 Column4
Sandeep Prasad Sharad Sachin
Ravi Ashish Mangesh NULL