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. problem getting sum of each row

problem getting sum of each row

Scheduled Pinned Locked Moved Database
questionhelp
5 Posts 4 Posters 0 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.
  • X Offline
    X Offline
    xoxoxoxoxoxox
    wrote on last edited by
    #1

    Hi, I'm trying to get total of each row in my table. For eample, I have columns x, y and z (all int). To get total, i'm writing "select (x + y + z) As total from myTable". It works fine as long as one of the colunm is not empty. If it finds any null data in x, y or z then total shows up null. How can i get total in such case? Thanks in advance

    E K R 3 Replies Last reply
    0
    • X xoxoxoxoxoxox

      Hi, I'm trying to get total of each row in my table. For eample, I have columns x, y and z (all int). To get total, i'm writing "select (x + y + z) As total from myTable". It works fine as long as one of the colunm is not empty. If it finds any null data in x, y or z then total shows up null. How can i get total in such case? Thanks in advance

      E Offline
      E Offline
      ednrgc
      wrote on last edited by
      #2

      Have you tried IsNull()?

      X 1 Reply Last reply
      0
      • X xoxoxoxoxoxox

        Hi, I'm trying to get total of each row in my table. For eample, I have columns x, y and z (all int). To get total, i'm writing "select (x + y + z) As total from myTable". It works fine as long as one of the colunm is not empty. If it finds any null data in x, y or z then total shows up null. How can i get total in such case? Thanks in advance

        K Offline
        K Offline
        Keith Malwitz
        wrote on last edited by
        #3

        Any expression containing a null value will evaluate to null. There are a couple of ways around this. You could define your database columns so that they are not allowed to contain null values, and assign them a default value of zero. Another method would be to test each value for null, and use 0 for the value of that operand if the result is true. Hope that helps.

        1 Reply Last reply
        0
        • E ednrgc

          Have you tried IsNull()?

          X Offline
          X Offline
          xoxoxoxoxoxox
          wrote on last edited by
          #4

          Thank you very much! IsNull worked fine.

          1 Reply Last reply
          0
          • X xoxoxoxoxoxox

            Hi, I'm trying to get total of each row in my table. For eample, I have columns x, y and z (all int). To get total, i'm writing "select (x + y + z) As total from myTable". It works fine as long as one of the colunm is not empty. If it finds any null data in x, y or z then total shows up null. How can i get total in such case? Thanks in advance

            R Offline
            R Offline
            RinkRat
            wrote on last edited by
            #5

            Could try something like: SELECT x,y,z, COALESCE(x,0) + COALESCE(y,0) + COALESCE(z,0) as [Row Total] FROM .............

            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