I’m using MS SQL, and here is my query…
SELECT SUM(Quantity) FROM table1
WHERE [item_no]='0052556'
AND [qty_to_ship] > 0
AND [type] = 5
Interestingly, the query as it stands above returns ‘NULL’…however, if I remove either one of the last 2 conditions it works fine (returns a real number)
to clarify, these queries work fine:
SELECT SUM(Quantity) FROM table1
WHERE [item_no]='0052556'
AND [type] = 5
and
SELECT SUM(Quantity) FROM table1
WHERE [item_no]='0052556'
AND [qty_to_ship] > 0
also note: ‘type’ is a PK, int, not null
what might be causing this?
Do you have a record that fullfils all the requirement in your (most restrictive) WHERE?
If not – there’s your anwer.
Edit: RedFilter’s comment is correct is well. You can add your own logic (ISNULL, etc.) in the SELECT Portion to change NULL to values you like (like 0, for instance)