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
what are acid properties? : Sql server database administration
What are the events recorded in a transaction log?
What are the advantages of sql azure?
How to select all columns of all rows from a table with a select statement in ms sql server?
Can You Use A Stored Procedure To Provide Data To An Ssrs Report?
what purpose does the model database serve? : Sql server database administration
What are different types of constraints?
Why we need to use secondry database file? though, we can do same work using primary database file also.
Can you explain how long are locks retained within the repeatable_read and serializable isolation levels, during a read operation with row-level locking?
What happens when converting big values to integers?
Explain trigger and its types?
How sql server executes a statement with nested subqueries?
How to check if stored procedure is running in sql server?
How to create stored procedures with parameters in ms sql server?
What are the different authentication modes in sql server?