Results 1 to 5 of 5
  1. #1
    aniyahudi is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    2

    Query to SUM two columns and consider null as 0 zero.

    BH
    Hi, I'm building a c# application using Visual Studio 2010, and connecting to Access Database. I'm trying to sum up two columns, but when one of the columns does not have any values, it should be considered as 0 (zero). I've tried the below Query in visual studio 2010, but it gives me an error saying "Undefined function 'IfISNull" in expression." Am i suppose to be adding some function in order to use the below code? Is the function suppose to be in Visual Studio or inside the Access database?

    SELECT SUM(IfISNull(AmountDebit)) - SUM(IfIsNull(AmountCredit)) AS Expr1 FROM Ledger GROUP BY PropertyID HAVING (PropertyID = ?)

    Thank you so much for your help.
    Aron


  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Info about Null http://allenbrowne.com/casu-12.html

    Use Nz() function.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    aniyahudi is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Jun 2014
    Posts
    2
    BH,
    hi thank you for your reply. I've tried the Nz function but I get the same message saying:"Undefined function 'Nz" in expression." by the way, I'm doing this directly the Visual Studio 2010 dataset.Maybe it's the Visual Studio that does not recognize Access functions?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Okay, Nz() is an Access/VBA function, even Excel doesn't like it.

    Then will have to use the long version with IIf():

    Sum(IIf(IsNull([AmountDebit]),0,[AmountDebit]))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    Is your SQL working in Access ?
    Code:
    SELECT SUM(IfISNull(AmountDebit)) - SUM(IfIsNull(AmountCredit)) AS Expr1 FROM Ledger GROUP BY PropertyID HAVING (PropertyID = ?)


Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 18
    Last Post: 02-14-2014, 05:06 PM
  2. Replies: 2
    Last Post: 08-16-2013, 01:36 AM
  3. Replies: 2
    Last Post: 05-17-2012, 03:52 PM
  4. Replies: 1
    Last Post: 02-23-2012, 02:27 PM
  5. Passing criteria "NULL" or "IS NOT NULL" to a query
    By SgtSaunders69 in forum Forms
    Replies: 1
    Last Post: 12-24-2011, 02:22 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums