Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2012
    Posts
    16

    Unanswered: Yearly Production

    I am attempting to sum the gas production for each organization number, and separate gas production into each year as such:

    Organization_Number 2008 2009 2010 2011 2012
    103 774 731 386 847 0

    But currently I am having trouble displaying this, and it's coming out as such:

    Organization_Number Month 2008 2009 2010 2011 2012
    103 1 774 731 386 847 NULL
    103 2 810 656 654 674 NULL
    202 1 2726 2702 2937 2512 2048
    202 2 2913 2051 2020 2064 NULL

    I want to remove the month and have one total per organization number, as well as remove NULL as show as 0.

    Code:
    select *
    from yearproduction
    pivot(
    sum(Gas_Prod)
    for Year in ([2008], [2009], [2010], [2011], [2012]))
    as YearlyProduction
    order by Organization_Number, Month

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Don't do this.
    Don't pivot in the database.
    Sum by Organization and Year, and then pivot the results in your reporting software.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •