Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2002
    Posts
    9

    Unanswered: Adding all non-null fields

    I have 50 fields that I would like to sum together in an sql statement. However, some of them may be null causing the statement to fail. Can someone send me a statement that would add up only fields that are not null.

    My current sql stmt is "select x1 + x2 + x3 + .... x50 from xtable"

    Thanks

  2. #2
    Join Date
    Dec 2001
    Location
    Toronto, Canada
    Posts
    335
    select ISNULL(x1,0)
    + ISNULL(x2,0)
    + ISNULL(x3,0)
    + ....
    + ISNULL(x50,0) from xtable
    MCDBA

  3. #3
    Join Date
    Sep 2002
    Posts
    9

    Thumbs up

    Thanks a lot.

Posting Permissions

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