Blog
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    APIs
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
 

Home >> Database >> Pivot tables in SqlServer 2005,2008
Pivot tables in SqlServer 2005,2008

In this blog I will give you a small introductory knowledge on pivot table. One thing important about pivot keyword that it is only supported by SqlServer2005 and later not SqlServer 2000 or 7.0 or 6.5.
Views: 6516     Comments: 0
by Awadhendra Tiwari on 5/11/2011

Pivot table in SQL Server 2005 and 2008

A pivot table is a program tool that allows you to reorganize and summarize selected columns and rows of data in a spreadsheet or database table to obtain a desired report. A pivot table doesn't actually change the spreadsheet or database itself. In database lingo, to pivot is to turn the data (see slice and dice) to view it from different perspectives.

 A pivot table is especially useful with large amounts of data. For example, a store owner might list monthly sales totals for a large number of merchandise items in an Excel spreadsheet. If the owner wanted to know which items sold better in a particular financial quarter, it would be very time-consuming for her to look through pages and pages of figures to find the information. A pivot table would allow the owner to quickly reorganize the data and create a summary for each item for the quarter in question.

Pivot tables display data in tabular form. The pivot table formatting is not different than a tabular report formatting but the table columns are formed by the report data itself. I mean as a pivot table example, your report creator can build a report with years and months in the left side of the table, the main product lines are displayed as columns, and total sales of each product line in the related year and month is displayed in the cell content.

Usage:-

Microsoft SQL Server has introduced the PIVOT and UNPIVOT commands as enhancements to t-sql with the release of MS SQL Server 2005. In MS SQL Server 2008, we can still use the PIVOT command and UNPIVOT command to build and use pivot tables in Sql. T-SQL Pivot and Unpivot statements will transform and rotate a tabular data into another table value data in Sql.Since Pivot / Unpivot are SQL2005 t-Sql enhancements, databases which you want to execute pivot and unpivot commands should be at least at compatibility level 90 (SQL2005) or 100 (SQL2008).

 T-SQL Pivot Syntax

T-SQL PIVOT syntax is not explicitly identified in the MSDN or on SQL Server BOL (Books Online) but general use of Pivot command can be summarized as follows:

SELECT  [non-pivoted column], -- optional  [additional non-pivoted columns], -- optional

  [first pivoted column],  [additional pivoted columns]

FROM (

  SELECT query producing sql data for pivot  -- select pivot columns as dimensions and

  -- value columns as measures from sql tables) AS Table Alias PIVOT (

  (column for aggregation or measure column) -- MIN,MAX,SUM,etc  FOR []  IN (

    [first pivoted column], ..., [last pivoted column]  )) AS PivotTableAliasORDER BY clause -- optional

Title :  
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
       
 
Report Abuse Form
Reason:    
 
Latest ArticleRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest Blogs by Awadhendra TiwariRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 3394
  
Copyright © 2009 - 2013MindStick. All Rights Reserved.