Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Setting values from a Pivot to 0?

Setting values from a Pivot to 0?

Scheduled Pinned Locked Moved Database
questioncareer
4 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    patsq
    wrote on last edited by
    #1

    How do I set value to zero in a Pivot? I would like to set the NULL values to zero from attached code

    Select * From
    (select Partner, Facility, PAY_PERIOD_BEGIN_DATE, PAY_PERIOD_END_DATE, Job_Code, Pay_ClassHrs, Pay_ClassAmount, Pay_Hours, Pay_Amount from #PremierFinal) as sourcetable
    PIVOT
    (
    sum(Pay_Hours)
    FOR Pay_ClassHrs in (PBS_Hrs, POT_Hrs, PED_Hrs, POR_Hrs, PJB_Hrs, PTO_Hrs, PWH_Hrs, PHR_Hrs, PNH_Hrs)
    )as pvt

    Quote:

    PBS_Hrs NULL NULL NULL NULL 792 278 NULL

    C 1 Reply Last reply
    0
    • P patsq

      How do I set value to zero in a Pivot? I would like to set the NULL values to zero from attached code

      Select * From
      (select Partner, Facility, PAY_PERIOD_BEGIN_DATE, PAY_PERIOD_END_DATE, Job_Code, Pay_ClassHrs, Pay_ClassAmount, Pay_Hours, Pay_Amount from #PremierFinal) as sourcetable
      PIVOT
      (
      sum(Pay_Hours)
      FOR Pay_ClassHrs in (PBS_Hrs, POT_Hrs, PED_Hrs, POR_Hrs, PJB_Hrs, PTO_Hrs, PWH_Hrs, PHR_Hrs, PNH_Hrs)
      )as pvt

      Quote:

      PBS_Hrs NULL NULL NULL NULL 792 278 NULL

      C Offline
      C Offline
      Chris Quinn
      wrote on last edited by
      #2

      Try using an ISNULL e.g. ISNULL(sum(Pay_hours),0)

      ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

      P 2 Replies Last reply
      0
      • C Chris Quinn

        Try using an ISNULL e.g. ISNULL(sum(Pay_hours),0)

        ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

        P Offline
        P Offline
        patsq
        wrote on last edited by
        #3

        It is not the SUM that I want to zero but the column values in

        FOR Pay_ClassHrs in (PBS_Hrs, POT_Hrs, PED_Hrs, POR_Hrs, PJB_Hrs, PTO_Hrs, PWH_Hrs, PHR_Hrs, PNH_Hrs)

        example:

        case when PBS_Hrs IS NULL then 0 end

        and so on... Thanks

        1 Reply Last reply
        0
        • C Chris Quinn

          Try using an ISNULL e.g. ISNULL(sum(Pay_hours),0)

          ========================================================= I'm an optoholic - my glass is always half full of vodka. =========================================================

          P Offline
          P Offline
          patsq
          wrote on last edited by
          #4

          I tried it but it comes back with Syntax error, my environment is MS SQL SERVER Management Studio 2016:

          FOR Pay_ClassHrs in (ISNULL(PBS_Hrs, 0), POT_Hrs, PED_Hrs, POR_Hrs, PJB_Hrs, PTO_Hrs, PWH_Hrs, PHR_Hrs, PNH_Hrs)

          Any ideas...!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups