i




 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How I use Pivot Operator in Sql Server ?
10-06-2010, 05:36 AM
Post: #1
How I use Pivot Operator in Sql Server ?
You can use the PIVOT and UNPIVOT relational operators to change a table-valued expression into another table. PIVOT rotates a table-valued expression by turning the unique values from one column in the expression into multiple columns in the output, and performs aggregations where they are required on any remaining column values that are wanted in the final output.

UNPIVOT performs the opposite operation to PIVOT by rotating columns of a table-valued expression into column values.

The syntax for PIVOT provides is simpler and more readable than the syntax that may otherwise be specified in a complex series of SELECT...CASE statements. For a complete description of the syntax for PIVOT, see FROM (Transact-SQL).

The following is annotated syntax for PIVOT.
Code:
SELECT <non-pivoted column>,

    [first pivoted column] AS <column name>,

    [second pivoted column] AS <column name>,

    ...

    [last pivoted column] AS <column name>

FROM

    (<SELECT query that produces the data>)

    AS <alias for the source query>

PIVOT

(

    <aggregation function>(<column being aggregated>)

FOR

[<column that contains the values that will become column headers>]

    IN ( [first pivoted column], [second pivoted column],

    ... [last pivoted column])

) AS <alias for the pivot table>

<optional ORDER BY clause>;

Here I am explaining a basic example of Pivot with the help of simple video..






Please give reputation if my answer/post is useful for you
Best Regards
Arti Gupta
Quote
10-06-2010, 06:13 AM
Post: #2
RE: How I use Pivot Operator in Sql Server ?
good effort arti... keep posting Smile

[Image: 2604595733.png]
Quote
10-06-2010, 09:54 AM
Post: #3
RE: How I use Pivot Operator in Sql Server ?
nice effort
simple and understandable
Quote
10-06-2010, 10:13 AM
Post: #4
RE: How I use Pivot Operator in Sql Server ?
Thanks.... Smile

Please give reputation if my answer/post is useful for you
Best Regards
Arti Gupta
Quote
10-07-2010, 10:15 AM
Post: #5
RE: How I use Pivot Operator in Sql Server ?
well done...
keep it up
u will make diffrence...
Quote
10-07-2010, 07:39 PM
Post: #6
RE: How I use Pivot Operator in Sql Server ?
Hi Arti


Posting video tutorial is a postive move.

saadia
Quote
10-08-2010, 04:24 AM
Post: #7
RE: How I use Pivot Operator in Sql Server ?
Thanks Saadia..... Smile

Please give reputation if my answer/post is useful for you
Best Regards
Arti Gupta
Quote
10-08-2010, 09:37 AM
Post: #8
RE: How I use Pivot Operator in Sql Server ?
Nice Effort.
But Very UnClear in the video
I think its my system resolution problem

Cheers!!!!!!
Rajesh Kumar Parbat
Quote
11-05-2010, 11:52 AM
Post: #9
RE: How I use Pivot Operator in Sql Server ?
Nice post . . .

Oracle Certified Trainer
[Image: signature.php?uid=40]
Quote




User(s) browsing this thread: 1 Guest(s)