Skip to Content
author's profile photo Former Member
Former Member

Trying to add up fields in query.

Hi I have a few user defined fields that are numeric fields and I want to add them together in a query. The problem is that sometimes one of the fields is null because it's blank and it won't add them together if one is null. How can I make it treat null fields as 0's?

Here's a sample of the query:

SELECT T0.[DocNum], (T0.[U_FREIGHT_1]+ T0.[U_FREIGHT_2]+ T0.[U_FREIGHT_3]+ T0.[U_FREIGHT_4]+ T0.[U_FREIGHT_5]+ T0.[U_FREIGHT_6]) FROM ORDR T0

In some cases T0.[U_FREIGHT_1] might be the only field with a value, in others all 6 could have a value and in others none of them may have a value.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on May 15, 2014 at 01:44 PM

    Hi,

    You nee to ISNULL function to get correct result.

    Follow below sample and same way change your query:

    SELECT isnull(T1.[U_F1],0) + isnull(T1.[U_F2],0) + isnull(T1.[U_F3],0) FROM ORDR T0 INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.[DocNum] = [%0]

    Thanks & Regards,

    Nagarajan

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.