July 23, 2010 at 3:38 am
Hello Everyone,
Can anyone tell me how can I convert displays records which come in rowwise into columnwise.
like
ID Name Salary
101 Rajesh 30000
102 Deepak 234000
103 Priyanka 222000
into
(Desired Result)
101 102 103
Rajesh Deepak Priyanks
30000 234000 222000
July 23, 2010 at 4:03 am
hi,
Your requirement is not Correct one...
How can you represent a column of different datatypes in a table as per Ur desired O/P
If you are using Pivot One column should remain same....
The following are the only possible ways......
SELECT * from tbl
pivot
(
MAX (Name) For ID in ([101],[102],[103])
) as Tmp
O/P:
==================
sal101102103
30000RajeshNULLNULL
222000NULLNULLPriyanka
234000NULLDeepakNULL
or
SELECT * from tbl
pivot
(
MAX (sal) For ID in ([101],[102],[103])
) as Tmp
O/P:-
=======================
name101102103
DeepakNULL234000NULL
PriyankaNULLNULL222000
Rajesh30000NULLNULL
Cheers!
Sasidhar Pulivarthi
July 23, 2010 at 4:08 am
Hello Mahesh, is it some sort of Homework u are working on? You sorted out that it is "PIVOT"ing.. so you would have attempted some code right? can you post what you have tried ? that request is very very simple.. i can give u the code right away, but taht wont make u learn, friend!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply