how can i substitute a NULL value for a 0 in an SQL Query result
SELECT EmployeeMaster.EmpNo, Sum(LeaveApplications.LeaveDaysTaken) AS LeaveDays
FROM EmployeeMaster FULL OUTER JOIN
LeaveApplications ON EmployeeMaster.id = LeaveApplications.EmployeeRecordID INNER JOIN
LeaveMaster ON EmployeeMaster.id = LeaveMaster.EmpRecordID
GRoup BY EmployeeMaster.EmpNo
order by LeaveDays Desc
with the above query, if an employee has no leave application record in table LeaveApplications, then their Sum(LeaveApplications.L开发者_开发知识库eaveDaysTaken) AS LeaveDays column returns NULL. What i would like to do is place a value of 0 (Zero) instead of NULL. I want to do this because i have a calculated column in the same query whose formular depends on the LeaveDays returned and when LeaveDays is NULL, the formular some how fails. Is there away i can put 0 for NULL such that that i can get my desired result.
SELECT EmployeeMaster.EmpNo, ISNULL(Sum(LeaveApplications.LeaveDaysTaken),0) AS LeaveDays
FROM EmployeeMaster FULL OUTER JOIN
LeaveApplications ON EmployeeMaster.id = LeaveApplications.EmployeeRecordID INNER JOIN
LeaveMaster ON EmployeeMaster.id = LeaveMaster.EmpRecordID
GRoup BY EmployeeMaster.EmpNo
order by LeaveDays Desc
You may want to use ISNULL
ISNULL(SUM(LeaveApplications.LeaveDaysTaken), 0) AS LeaveDays
Use the isnull
function.
精彩评论