Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning NULLs when subtracting with a NULL 1

Status
Not open for further replies.

GShort

MIS
Apr 20, 2005
70
US
I have the following select code:

Code:
 SELECT dbo.SOP30200.CUSTNMBR,
sum(CASE WHEN dbo.SOP30200.SOPNUMBE LIKE 'A-%' or dbo.SOP30200.SOPNUMBE LIKE 'I-%' THEN cast(dbo.IV00101.USCATVLS_1 as numeric(2)) END) - sum(CASE WHEN dbo.SOP30200.SOPNUMBE LIKE 'RET-%' THEN cast(dbo.IV00101.USCATVLS_1 as numeric(2)) END) AS PointTotal
FROM         dbo.IV00101 INNER JOIN
dbo.SOP30300 ON dbo.IV00101.ITEMNMBR = dbo.SOP30300.ITEMNMBR INNER JOIN
dbo.SOP30200 ON dbo.SOP30300.SOPNUMBE = dbo.SOP30200.SOPNUMBE
WHERE     (dbo.IV00101.USCATVLS_1 > '0')
GROUP BY dbo.SOP30200.CUSTNMBR
order by custnmbr

But when I run it I am getting back NULLs when ever I have a NULL on returns field (the subtraction part of the query). I can break it into two fields and do the equation later if I have to but it is not desired.

Thanks for any help.
 
Check for NULL with IsNull in the equation

ISNULL ( check_expression , replacement_value )

something like ISNULL(thecol, 0)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top