In Microsoft SQL Server 2008, I want to do the following:
UPDATE dbo.Test SET
Earned=(
SELECT Points
FROM dbo.Answer
WHERE AnswerID = Guess_AnswerID
AND Correct=1
)
The problem is when correct=0, then the select is null and Earned needs to be 0 instead of null.
Add IsNull around any 2 expressions. You can also use Coalesce in this case.
You may also be looking to sum all the points on each matching answer. If that’s the case, you need to make it Sum(Points) instead of just Points.