how to change column into row in sql

Answers were Sorted based on User's Feedback



how to change column into row in sql..

Answer / kapil

With the help of pivot table in sql server 2005 we can do so

Is This Answer Correct ?    22 Yes 5 No

how to change column into row in sql..

Answer / vishal

with the help of pivoting....
it will solve the problem of grouping also

Is This Answer Correct ?    0 Yes 0 No

how to change column into row in sql..

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

how to change column into row in sql..

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

Post New Answer

More SQL Server Interview Questions

How we create SQL Server 2005 Reporting Services ? Give me Sample

0 Answers   HCL,


What is not null constraint?

0 Answers  


What do you understand by hotfixes and patches in sql server?

0 Answers  


How to access the inserted record of an event?

0 Answers  


How can I know what query is executing by by a particural user? (using sp id or any othe way.)

2 Answers  






event classes in sql server

2 Answers   Accenture, AFE,


What is a data source or ds? : sql server analysis services, ssas

0 Answers  


how to count datewise data in sqlserver

4 Answers   CarrizalSoft Technologies, IndusInd Bank,


Which database stores information about replication?

0 Answers  


how to write test cases for testing databases,especially for testing and writing test cases for stored procedures.any real time database testers.please answer me.

0 Answers  


Using the customer, and order table in northwind database, please write a query to produce xml?

0 Answers  


What does it mean to invest in the index?

0 Answers  


Categories