how to change column into row in sql
Answers were Sorted based on User's Feedback
Answer / kapil
With the help of pivot table in sql server 2005 we can do so
Is This Answer Correct ? | 22 Yes | 5 No |
Answer / vishal
with the help of pivoting....
it will solve the problem of grouping also
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / samba shiva reddy . m
creating pivot table:
Columns as Rows
below statement will give as it is data
select
PS.Name, P.Color, PIn.Quantity
from Production.Product P
inner join Production.ProductSubcategory PS
on PS.ProductSubcategoryID = P.ProductSubcategoryID
left join Production.ProductInventory PIn
on P.ProductID = PIn.ProductID
This statement will change the columns as rows
select
*
from
(
select
PS.Name, P.Color, PIn.Quantity
from Production.Product P
inner join Production.ProductSubcategory PS
on PS.ProductSubcategoryID = P.ProductSubcategoryID
left join Production.ProductInventory PIn
on P.ProductID = PIn.ProductID
) DataTable
PIVOT
(
SUM(Quantity)
FOR Color
IN (
[Black],[Blue],[Grey],[Multi],[Red],
[Silver],[Silver/Black],[White],[Yellow]
)
) PivotTable
Is This Answer Correct ? | 2 Yes | 4 No |
Answer / sai
I agree with this answer..and also we can do the pivot
transaformation in SSIS.
Is This Answer Correct ? | 1 Yes | 4 No |
How to find the second largest salary in the emp database and also How to find 3rd,4th and so on ........ in the emp database plz mail the answer @ mak2786@gmail.com
35 Answers Oracle, Scend, TechInfini,
How can you start sql server in different modes?
what is unique and xaml nonclustered index
what's the information that can be stored inside a bit column? : Sql server database administration
What is not null constraint?
Can foreign key be duplicate?
Can group functions be mixed with non-group selection fields in ms sql server?
What is meant by Active-Passive and Active-Active clustering setup?
Describe and explain about SQL native client?
Explain fundamentals of Data ware housing & OLAP?
What is transaction server explicit transaction?
What are types of subqueries?