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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum/isnull question 1

Status
Not open for further replies.
Nov 7, 2002
61
US
I'm running a query to return a field "LOS" that I then want to run an aggregate Sum() function on. The problem is, I've used isnull() on both the initial query and then on the sum query and it's still coming up null.

Suggestions?

Code:
DROP TABLE #DishDays
SELECT c.AcctNum, isnull(DateDiff(d,AdmitDate,DischargeDate),0)AS LOS 
INTO #DishDays
FROM #DishDaysKMPBO c
WHERE StartDate<=AdmitDate 
AND DischargeDate<=EndDate

Code:
select sum(isnull(Los,0)) as SumLos
         from #DishDays

I need it to return a 0, as I have another query that totals the sums of several queries (including this one) and it's making the total of that query result in a null.
 
try this (not tested)

Code:
select coalesce(sum(Los), 0) as sumLos
from #DishDays

Ignorance of certain subjects is a great part of wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top