このストアド プロシージャの結果は、クエリに基づいて合計で保存されます。合計でレコードがない場合は、結果に 0 が必要です。どのように null 値を管理できますか。
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