ALTER procedure [dbo].[Usp_sel_Result] 2,4019,2027
@Userid int =null,
@QuestionId int=null,
@ExamId int =null
As
begin
SELECT [UserId]
,[QuestionId]
,[ExamId]
,[QuestionName]
,[OptionOne]
,[OptionSecond]
,[OptionThird]
,[OptionForth]
,[TrueAnswer],
convert(int, [dbo].UserAnswer.[YourAnswer]) as [YourAnswer],
convert(int, 0) as score,
convert(int, 0) as totalscore
INTO #tmp
FROM [dbo].UserAnswer
where
CASE WHEN isnull(@UserId, 0) = 0
THEN 0
ELSE [dbo].UserAnswer.UserId
END = isnull(@UserId, 0)
AND CASE WHEN isnull(@ExamId, 0) = 0
THEN 0
ELSE [dbo].UserAnswer.ExamId
END = isnull(@ExamId, 0)
update #tmp
set score = 1
where [TrueAnswer] = [YourAnswer]
declare @totalscore int
select @totalscore = sum(#tmp.score) from #tmp
update #tmp
set totalscore = @totalscore
select * from #tmp
END
What I have tried:
var score = db.sel_Result(UserId, QuestionId, ExamId);
ViewBag.totalscore = score;
var score = db.sel_Result(i => new { i.UserId, i.QuestionId, i.ExamId }).ToList());