Of the three elements you should identify for a PIVOT, which one is not actually included in the PIVOT expression? Why? How can it be remedied?
SQL Server 70-461 05-02
How does the FOR <spreading column> IN (<distinct spreading values>) work?
SQL Server 70-461 05-02
What if the distinct spreading values are irregular?
SQL Server 70-461 05-02
How many aggregate functions can you use in PIVOT?
Only 1
SQL Server 70-461 05-02
Can the IN clause in PIVOT take a dynamic list of values?
SQL Server 70-461 05-02
What aggregate function can’t be used with PIVOT? And what is the work around?
SQL Server 70-461 05-02
What is the assigned data type to the values column you define when unpivoting?
Same as it was when pivoted.
SQL Server 70-461 05-02
What three elements need to be identified in a PIVOT query?
SQL Server 70-461 05-02
General recommended form of a PIVOT query
--Create a CTE with only the columns needed for your PIVOT WITH PivotData AS ( SELECT <grouping column>, <spreading column>, <aggregation column> FROM <table name> ) SELECT <select list> FROM PivotData PIVOT( <aggregate function>(<aggregate columns>) FOR <spreading column> IN(<distinct spreading values>) ) AS P;
select list= name of grouping column and names of value columns. Ex. (custid, [1], [2], [3])
SQL Server 70-461 05-02
Of the three PIVOT elements, which two cannot directly be a result of an expression and what is the work around for this?
SQL Server 70-461 05-02
What does it mean that PIVOT and UNPIVOT are table operators?
SQL Server 70-461 05-02
What is the basic format for the UNPIVOT statement?
--General form to UNPIVOT data SELECT <column list>, <names column>, <values column> FROM <table name> UNPIVOT(<values column> FOR<names column> IN(<source columns>) ) AS u;
You will know the source column names since they already exist. When you UNPIVOT them you have to choose the names column name which will list what were column names in PIVOT.
You will also have to decide values column name which will list what used to be aggregate value in PIVOT.
SQL Server 70-461 05-02
Example of an UNPIVOT statement using test data from the book
--Example to UNPIVOT data SELECT custid, --column list shipperid, --names column freight --values column FROM PivotData --table name UNPIVOT( freight --values column FOR shipperid --names column IN([1], [2], [3]) ) ) AS u;
You will know the source column names since they already exist. When you UNPIVOT them you have to choose the names column name which will list what were column names in PIVOT.
You will also have to decide values column name which will list what used to be aggregate value in PIVOT.
SQL Server 70-461 05-02
What is the assigned data type to the names column you define when unpivoting?
nvarchar(128)
SQL Server 70-461 05-02