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

Different Types of Functions ?

2 Answers   Satyam,


hi, how to link a text file and a .rpt file in my tables of sql server and to retrieve those records for further use. reply me as soon as possible.

0 Answers  


Which table keeps the locking information?

0 Answers  


What are data files?

0 Answers  


What is the preferred way to create a clustered and non-clustered index? Which index should you create first the clustered or non-clustered?

0 Answers  






What is BCP? When do we use it?

2 Answers  


How do I change my passwords (database, LDAP, and so on) without causing an outage?

0 Answers   IBM,


what is differencial backup?how to work?Anybody explai it?

2 Answers   HCL,


Give main differences between "Truncate" and "Delete".

0 Answers   HCL,


Can we make the the chages By Using the Sql if u know any function or process please inform me Actuall result: BRK1 Break 1 Part 1 00:01:00:00 60 BRK1 Break 1 Part 2 00:01:00:00 60 BRK2 Break 2 Part 1 00:01:00:00 60 BRK2 Break 2 Part 2 00:01:00:00 60 BRK2 Break 2 Part 3 00:01:00:00 60 BRK3 Break 3 Part 1 00:01:00:00 60 BRK3 Break 3 Part 2 00:01:00:00 60 Desired O/P: BRK1 Break 1 Part 1 00:01:00:00 60 Part 2 00:01:00:00 60 BRK2 Break 2 Part 1 00:01:00:00 60 Part 2 00:01:00:00 60 Part 3 00:01:00:00 60

0 Answers   Satyam,


how to avoid cursors? : Sql server database administration

0 Answers  


Does sql server use t sql?

0 Answers  


Categories