getting return values from stored procedures

  • Thread starter Thread starter Phil Townsend
  • Start date Start date
P

Phil Townsend

I need to get a return value from the procedure that follows. For some
reason I am not able to asign a value to @returnval and get it back to
the C# code executing it. The procedure does not return any errors. Here
is the code:

ALTER PROCEDURE gradeTest2
@empid int, @testid int
AS
set nocount on

declare @returnval int
set @returnval=1
declare @correct int
declare reader cursor fast_forward for
select answercorrect from questionsanswered where (empid=@empid) and
(testid=@testid)
open reader
fetch next from reader into @correct
while @@Fetch_Status=0
begin
if @correct=0
set @returnval=0
fetch next from reader into @correct
end
close reader
deallocate reader

begin
if @returnval=1
if not exists (select testid from testresults where (empid=@empid)
and (testid=@testid))
insert into testresults (testid,empid,results,testdate)
values (@testid,@empid,@returnval,getdate())
else
update testresults set results=@returnval,testdate=getdate()
where (empid=@empid) and (testid=@testid)
if @returnval=1
delete from questionsanswered where (empid=@empid) and
(testid=@testid)


return @returnval
end
 
Let's see the code you used to execute this SP. What is this SP trying to
do?

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Back
Top