Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

how to change column into row in sql

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


Please Help Members By Posting Answers For Below Questions

what are acid properties? : Sql server database administration

1056


What are the events recorded in a transaction log?

1043


What are the advantages of sql azure?

140


How to select all columns of all rows from a table with a select statement in ms sql server?

1188


Can You Use A Stored Procedure To Provide Data To An Ssrs Report?

151


what purpose does the model database serve? : Sql server database administration

1024


What are different types of constraints?

968


Why we need to use secondry database file? though, we can do same work using primary database file also.

7005


Can you explain how long are locks retained within the repeatable_read and serializable isolation levels, during a read operation with row-level locking?

1034


What happens when converting big values to integers?

1053


Explain trigger and its types?

1114


How sql server executes a statement with nested subqueries?

1088


How to check if stored procedure is running in sql server?

1121


How to create stored procedures with parameters in ms sql server?

1150


What are the different authentication modes in sql server?

1164