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
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