The PIVOT operator rotates rows into columns, optionally performing aggregations or other mathematical calculations along the way. It widens the input table expression based on a given pivot column and generates an output table with a column for each unique value in the pivot column. The UNPIVOT operator performs an operation opposite to the one PIVOT performs; it rotates columns into rows. The UNPIVOT operator narrows the input table expression based on a pivot column.
For eg:
SELECT CAST(YEAR(SaleDate) AS VARCHAR(4)), BigScreen, PoolTable, Computer FROM SalesHistory PIVOT
( SUM(SalePrice) FOR Product IN(BigScreen, PoolTable, Computer)
) AS p
If you have the better answer, then send it to us. We will display your answer after the approval.
Can we generate a trigger for two tables? if so what is the query to generate a trigger for two tables employee table and department table with employee having department no.
I was asked in an interview... "Suppose u have a field with UNIQUE KEY. can u leave two or more cells NULL in SQL Server 2005...If Yes then Why...if NOT then Why.....