how to change column into row in sql

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the types of containers in ssis?

598


How to get all stored procedures in sql server?

504


Do you know what is recursion? Is it possible for a stored procedure to call itself or recursive stored procedure?

536


What is create statement?

523


How can sql server instances be hidden?

524






Please explain what is “asynchronous” communication in sql server service broker?

506


Mention the different authentication modes in sql server.

525


Tell me about normalization in DBMS.

576


What are the properties of sub-query?

572


How to use go command in "sqlcmd"?

640


what is a transaction? : Sql server database administration

469


What do you mean by an execution plan?

560


Does partitioning help performance?

525


how to trace the traffic hitting a sql server? : Sql server database administration

1121


what are user defined datatypes? : Sql server database administration

514