以下是我的发言:
SELECT
CASE
WHEN @UserRole = 1 THEN 1
ELSE 0
END AS [CanEdit],
F.FundingStreamName
FROM FundingStream AS F
LEFT JOIN Projects AS P ON P.FundingStream = F.FundingStreamID
WHERE ProjectNumber = @ProjectNumber
我注意到如果FundingStreamID
为空,case语句也不会返回任何内容,无论是否有资金流,我如何才能执行case语句?感谢。
答案 0 :(得分:0)
我认为问题在于你的where
条款是"撤消"你的左外连接。尝试将条件移至on
子句:
SELECT (CASE WHEN @UserRole = 1 THEN 1
ELSE 0
END) AS [CanEdit],
F.FundingStreamName
FROM FundingStream F LEFT JOIN
Projects P
ON P.FundingStream = F.FundingStreamID AND
P.ProjectNumber = @ProjectNumber ;
答案 1 :(得分:0)
使用@MicSim回答:
SELECT
CASE
WHEN @UserRole = 1 THEN 1
ELSE 0
END AS [CanEdit],
F.FundingStreamName
FROM FundingStream AS F
RIGHT JOIN Projects AS P ON P.FundingStream = F.FundingStreamID
WHERE ProjectNumber = @ProjectNumber
再次感谢您的帮助!