Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
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]

  ----select * from #tmp

  declare @totalscore int

  select @totalscore = sum(#tmp.score) from #tmp 

  update  #tmp
  set totalscore = @totalscore

  select * from #tmp

END


What I have tried:

C#
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());
Posted
Updated 8-Jul-18 20:10pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900