vidhya

vidhya

  • NA
  • 324
  • 88.3k

How do i call my stored procedure in mvc3 razor application

Jul 2 2013 2:22 AM
this is my stored procedure which i created. I added in my .edmx file by clicking "update database model".

How do i call the procedure in mvc3razor application using c#.

CREATE PROCEDURE GetGradeBook
AS
BEGIN

DECLARE @AssignmentList varchar(3000),@Sql varchar(max)
SET @AssignmentList =STUFF((SELECT DISTINCT ',[' + assignmentname + ']' FROM assignment where coursesectionid='b78a6efe-ac77-4e49-806a-fc2fad71068b' FOR XML PATH('')),1,1,'')

SET @Sql ='select *
from
(
select p.firstname,p.lastname,a.assignmentname,a.pointspossible
from person2 p
inner join coursesectionroster cs
on cs.personid = p.personid
inner join assignment a
on a.coursesectionid = cs.coursesectionid
left join assignmentsubmission asg
on a.assignmentid=asg.assignmentid
where cs.coursesectionid=''b78a6efe-ac77-4e49-806a-fc2fad71068b''
and cs.courserole=2
)t
PIVOT(SUM(pointspossible) FOR assignmentname IN(' + @AssignmentList + '))p'

EXEC (@SQL)
END

Answers (15)