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

Explain different backup plans?

0 Answers  


What is difference between createstatement and preparedstatement?

0 Answers  


How to write an inner join with the where clause in ms sql server?

0 Answers  


Which command executes the contents of a specified file?

2 Answers   ABC, InfoMedia,


Explain what are commit and rollback in sql?

0 Answers  






What is ssl in sql server?

0 Answers  


what is a traditional network library for sql servers? : Sql server database administration

0 Answers  


What is the difference between online clustering and Offline clustering?

0 Answers   IBM,


Can a database be shrunk to 0 bytes, if not, why?

0 Answers  


Explain time data type in sal server 2008?

0 Answers  


If we use where clause in the left outer join then how the query would behave/act?

1 Answers  


What is a constant or literal in ms sql server?

0 Answers  


Categories