Casual Articles
#1 in Business Subscribe Email Print

You are here: Home > Computers and Technology > Software > Pivot And Unpivot

Tags

  • ownership
  • declare
  • joinedon datetime
  • artificial intelligence
  • another exampleexample

  • Links

  • Baby Steps
  • New Lease Car Buying Guide
  • Wysiwyg?
  • Casual Articles - Pivot And Unpivot

    Advantages/Disadvantages to Apartment Ownership In Abbotsford BC - Secrets Revealed
    In any situation of shared ownership the community living life style will offer you positive and negative angles. This can be related to townhouses and all other attached properties in the Fraser Valley and Lower Mainland area’s.Advantages1. Enjoy – the availability of amenities su
    S Yr2002,

    [2003] AS Yr2003,

    [2004] AS Yr2004 FROM ( SELECT StudentName,

    CollegeName,

    YEAR(JoinedOn) Yr

    FROM @tblStudents ) ts PIVOT ( Count(StudentName) FOR Yr IN ( [2001] , [2002] , [2003] , [2004] ) ) tp

    Here is another example

    Example

    Why You Should Never Quit Your MLM
    Listen to this and tell me if it sounds familiar to you. You’ve looked over all the material and decided to join a new mlm company, maybe your first one, maybe not. The products look great, the company looks professional, the promo material is slick, and the website has a flash presentation. T
    If you have ever worked with Microsoft Access, you might have used the TRANSFORM statement to create a crosstab query. Even though the similar functionality was missed in sql server 2000, we can achieve the same in SQL Server 2005 via the PIVOT operator with the SELECT statement. The PIVOT operator can be used to transform a set of rows into columns while the UNPIVOT operator complements the PIVOT operator by allowing you to turn columns into rows.

    Here is an example

     DECLARE @tblStudents table (

    StudentID INT IDENTITY,

    StudentName VARCHAR(100),

    CollegeName VARCHAR(100),

    JoinedOn DATETIME ) INSERT INTO @tblStudents SELECT 'Zero','College_One','20010101' UNION ALL SELECT 'One','College_One','20010102' UNION ALL SELECT 'Two','College_One','20010202' UNION ALL SELECT 'Three','College_Two','20010202' UNION ALL SELECT 'Four','College_One','20020302' UNION ALL SELECT 'Five','College_One','20030202' UNION ALL SELECT 'Six','College_Two','20040202' UNION ALL SELECT 'Seven','College_Two','20040202' UNION ALL SELECT 'Eight','College_Three','20040202'

    SELECT * FROM @tblStudents

    SELECT CollegeName,

    [2001] AS Yr2001,

    [2002] AS Yr2002,

    [2003] AS Yr2003,

    [2004] AS Yr2004 FROM ( SELECT StudentName,

    CollegeName,

    YEAR(JoinedOn) Yr

    FROM @tblStudents ) ts PIVOT ( Count(StudentName) FOR Yr IN ( [2001] , [2002] , [2003] , [2004] ) ) tp

    Here is another example

    Example2

    Artificial Intelligence and Use of Appendix Archiving Systems for Memory Storage
    Data Storage for artificial intelligence is a crucial issue and indeed quite serious as artificial intelligent systems will be programming themselves. This means that each time they make a new page of data sets perhaps in an XML spreadsheet, to be used as part of the decision matrix for future de
    used to transform a set of rows into columns while the UNPIVOT operator complements the PIVOT operator by allowing you to turn columns into rows.

    Here is an example

     DECLARE @tblStudents table (

    StudentID INT IDENTITY,

    StudentName VARCHAR(100),

    CollegeName VARCHAR(100),

    JoinedOn DATETIME ) INSERT INTO @tblStudents SELECT 'Zero','College_One','20010101' UNION ALL SELECT 'One','College_One','20010102' UNION ALL SELECT 'Two','College_One','20010202' UNION ALL SELECT 'Three','College_Two','20010202' UNION ALL SELECT 'Four','College_One','20020302' UNION ALL SELECT 'Five','College_One','20030202' UNION ALL SELECT 'Six','College_Two','20040202' UNION ALL SELECT 'Seven','College_Two','20040202' UNION ALL SELECT 'Eight','College_Three','20040202'

    SELECT * FROM @tblStudents

    SELECT CollegeName,

    [2001] AS Yr2001,

    [2002] AS Yr2002,

    [2003] AS Yr2003,

    [2004] AS Yr2004 FROM ( SELECT StudentName,

    CollegeName,

    YEAR(JoinedOn) Yr

    FROM @tblStudents ) ts PIVOT ( Count(StudentName) FOR Yr IN ( [2001] , [2002] , [2003] , [2004] ) ) tp

    Here is another example

    Example

    How To Avoid Network Marketing Failure
    Contrary to what most people believe…failing network marketing can actually be a “hard” thing to do. Let me explain why.Did you know that 95% of every single network marketer who has stuck with their company for 10 years has reached the highest level of their company’s compensation plan?

    JoinedOn DATETIME ) INSERT INTO @tblStudents SELECT 'Zero','College_One','20010101' UNION ALL SELECT 'One','College_One','20010102' UNION ALL SELECT 'Two','College_One','20010202' UNION ALL SELECT 'Three','College_Two','20010202' UNION ALL SELECT 'Four','College_One','20020302' UNION ALL SELECT 'Five','College_One','20030202' UNION ALL SELECT 'Six','College_Two','20040202' UNION ALL SELECT 'Seven','College_Two','20040202' UNION ALL SELECT 'Eight','College_Three','20040202'

    SELECT * FROM @tblStudents

    SELECT CollegeName,

    [2001] AS Yr2001,

    [2002] AS Yr2002,

    [2003] AS Yr2003,

    [2004] AS Yr2004 FROM ( SELECT StudentName,

    CollegeName,

    YEAR(JoinedOn) Yr

    FROM @tblStudents ) ts PIVOT ( Count(StudentName) FOR Yr IN ( [2001] , [2002] , [2003] , [2004] ) ) tp

    Here is another example

    Example

    A Risky Investment Becomes Commonplace
    It was not that long ago that investors heard the words ‘Commodity Investments’ and for the most part ran the other way. These investments meant investing in the highly leveraged and volatile futures markets, something most investment advisor’s would tell their clients to stay clear of.Now
    ON ALL SELECT 'Five','College_One','20030202' UNION ALL SELECT 'Six','College_Two','20040202' UNION ALL SELECT 'Seven','College_Two','20040202' UNION ALL SELECT 'Eight','College_Three','20040202'

    SELECT * FROM @tblStudents

    SELECT CollegeName,

    [2001] AS Yr2001,

    [2002] AS Yr2002,

    [2003] AS Yr2003,

    [2004] AS Yr2004 FROM ( SELECT StudentName,

    CollegeName,

    YEAR(JoinedOn) Yr

    FROM @tblStudents ) ts PIVOT ( Count(StudentName) FOR Yr IN ( [2001] , [2002] , [2003] , [2004] ) ) tp

    Here is another example

    Example

    IT Marketing: Know the Decision Maker
    Know exactly whom the decision maker is that you're trying to target before you start your IT marketing and prospecting. In this article, you'll learn why it's extremely important that you define as tightly as you can who the decision maker is, and how to do that.If there's a particular in
    S Yr2002,

    [2003] AS Yr2003,

    [2004] AS Yr2004 FROM ( SELECT StudentName,

    CollegeName,

    YEAR(JoinedOn) Yr

    FROM @tblStudents ) ts PIVOT ( Count(StudentName) FOR Yr IN ( [2001] , [2002] , [2003] , [2004] ) ) tp

    Here is another example

    Example2

     USE AdventureWorks

    SELECT EmployeeID,

    [2002] Yr2002,

    [2003] Yr2003,

    [2004] Yr2004 FROM ( SELECT YEAR(OrderDate) OrderYear,

    EmployeeID,

    TotalDue

    FROM Purchasing.PurchaseOrderHeader ) poh PIVOT ( SUM(TotalDue) FOR OrderYear IN ( [2002] , [2003] ,[2004] ) ) pvt ORDER BY EmployeeID

    Example 3:

     DECLARE @tab TABLE (id INT IDENTITY, status VARCHAR(1000))
     INSERT INTO @Tab SELECT 'Completed'
     INSERT INTO @Tab SELECT 'Submitted'
     INSERT INTO @Tab SELECT 'InProgress'
     INSERT INTO @Tab SELECT 'Submitted'
     INSERT INTO @Tab SELECT 'Completed'

    SELECT [Submitted],[Completed] , [InProgress] FROM (

    SELECT Status, COUNT(*) cnt FROM @Tab GROUP BY Status )t PIVOT (SUM(cnt) FOR Status IN ([Submitted],[Completed] , [InProgress]) )a

    HTTP = HTML link (for blogs, profiles,phorums):
    <a href="http://www.casualarticles.com/article/177445/casualarticles-Pivot-And-Unpivot.html">Pivot And Unpivot</a>

    BB link (for phorums):
    [url=http://www.casualarticles.com/article/177445/casualarticles-Pivot-And-Unpivot.html]Pivot And Unpivot[/url]

    Related Articles:

    As A Small Business, Why Do You Need A Website?

    Sell Homes and Have Fun!

    DVR Cards

    Bookmark it: del.icio.us digg.com reddit.com netvouz.com google.com yahoo.com technorati.com furl.net bloglines.com socialdust.com ma.gnolia.com newsvine.com slashdot.org simpy.com shadows.com blinklist.com