这个存储过程的结果是在查询的基础上总共存储的,如果总共没有任何记录那么结果中要0,如何管理空值。
CREATE PROCEDURE dbo.Procedure_Summary
@UserID INT ,
@Year INT
AS
BEGIN
/* Procedure body */
SELECT UserID,
UserName ,
[Marks1] as 'English',
[Marks2] as 'Maths',
[Marks3] as 'Science'
FROM
(
SELECT l.UserID,
e.UserName ,
s.SubjectName,
TotalMarks AS Total
FROM ViewLeave l
INNER JOIN SubjectType s ON s.SubjectID = l.SubjectID
INNER JOIN UserInfo e ON e.UserID = l.UserID
WHERE (( l.Result = 'Pass')
AND ( e.UserID = @UserID)
AND l.[year]=@Year)
GROUP BY s.SubjectName,l.UserID, e.UserName ,TotalDays
)ps
pivot
(
SUM(Total)
FOR SubjectName IN ([Marks1],[Marks2],[Marks3])
) AS pvt
END
目前的结果和预期的结果是——
Accoding to current stored procedure result are as ,
UserID UserName English Maths Science
105 ABC 25 0 36
106 XYZ 26 88 88
But i want if all three subject marks are 0 means total are zero and then show
as , also show non zero record
UserID UserName English Maths Science
109 QWE 0 0 0