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 create a login account in ms sql server to access the database engine using "create login" statements?
What is the purpose of UPDATE STATISTICS?
How to see the event list of an existing trigger using sys.trigger_events?
Does server sql treat char as a variable-length or fixed-length column?
What do you know about normalization and de- normalization?
What stored by the msdb?
Can you explain the role of each service?
Explain indexed views and partitioned view with their syntax.
Why I am getting this error when dropping a database in ms sql server?
What are the difference between “where” and “having” clause in sql server?
How to Debug a Stored Procedure?
why would you call update statistics? : Sql server database administration
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)