很简单的问题,为什么我写不对!
create procedure msp_cstj
( @ClassID char(4) )
As
Begin
SET NOCOUNT OFF
declare @mySql varchar(1024)
declare @stlx char(1),@stdm varchar(20),@mSfzq char(1),@mCwcs int
declare @TabName varchar(20)
declare @OldStdm varchar(20),@OldStlx char(1)
if (Select Count(*) from sysobjects where name = 'Ls_TabTF' and type = 'U') > 0
drop table Ls_TabTF
Create table Ls_TabTF (stdm varchar(20),mc varchar(2000),cwcs char(6))
if (Select count(*) from sysobjects where name = 'Ls_TabJL' and type = 'U' )>0
drop table Ls_TabJL
Create table Ls_TabJL (stdm varchar(20),stlx char(1),sfzq char(1))
select @mySql = 'Insert into Ls_TabJL select stdm,stlx,sfzq from zcjl where sfzq = 0 and kbh = '''+@ClassID+''''
execute(@mySql)
select @mySql = 'Insert into Ls_TabJL select stdm,stlx,sfzq from xscsjl where sfzq = 0 and kbh = '''+@ClassID+''''
execute(@mySql)
select @mCwcs = 1
select @OldStdm = ''
select @OldStlx = ''
declare cur_tx cursor for select * from Ls_TabJL
open cur_tx
fetch cur_tx into @stdm,@stlx,@msfzq
while @@fetch_status = 0
Begin
if (select count(*) from Ls_TabJL where stdm=''''+@stdm+'''')=0
begin
select @mCwcs = 1
select @TabName = dybm from jctxms where sttx = @stlx
select @mySql = 'Insert Into Ls_TabTF select stdm, tm,''' + convert(char(10),@mCwcs) + ''' from ' + @TabName + ' where stlx = ''' + @stlx + ''' and stdm = ''' + @stdm + ''''
end
else
begin
select @mySql = 'update Ls_TabTF set cwcs =convert(char(10),convert(int(4),cwcs)+1) where stdm ='''+@stdm+''''
end
Execute(@mySql)
select @OldStdm = @stdm
select @OldStlx = @stlx
fetch cur_tx into @stdm,@stlx,@msfzq
End
Close cur_tx
Deallocate cur_tx
select * from Ls_TabTF order by cwcs desc
SET NOCOUNT ON
End
go
这是我写的存储过程中的一部分。我想实现的是:统计一到题目出错的次数。可是我现在得到的结果是所有出错的题目次数都是一,他不统计相加!