If you no longer need two component variables, you can (re) use one of the variables:
SET @QuestionPoints = ... SET @EventPoints = ... SET @QuestionPoints = @QuestionPoints + @EventPoints
Be careful when adding SUM() 's, because they can be NULL. 20 + null => null . Use ISNULL if necessary, e.g.
SET @QuestionPoints = isnull(@QuestionPoints, 0) + isnull(@EventPoints, 0)
If you still need them, you can declare a third.
DECLARE @TotalPoints float --- or numeric or whatever the type should be SET @TotalPoints = @QuestionPoints + @EventPoints
You can even skip individual variables
SET @QuestionPoints = (SELECT SUM(POINTS) FROM tb_Responses WHERE UserID = @UserId AND ID = @ID) + (SELECT SUM(dbo.tb_Events.Points) FROM dbo.tb_Attendance INNER JOIN dbo.tb_Events ON dbo.tb_Attendance.EventID = dbo.tb_Events.dbID WHERE dbo.tb_Attendance.UserID = @UserID AND dbo.tb_Attendance.DidAttend = 'Y' AND dbo.tb_Events.ID = @ID)
RichardTheKiwi
source share