很简单的问题,为什么我写不对!

houlinghouling 2003-12-12 04:38:55
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
这是我写的存储过程中的一部分。我想实现的是:统计一到题目出错的次数。可是我现在得到的结果是所有出错的题目次数都是一,他不统计相加!
...全文
53 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
vileboy 2003-12-15
  • 打赏
  • 举报
回复
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 exists(Select 1 from sysobjects where name = 'Ls_TabTF' and type = 'U')
drop table Ls_TabTF

Create table Ls_TabTF (stdm varchar(20),mc varchar(2000),cwcs char(6))

if exists(Select 1 from sysobjects where name = 'Ls_TabJL' and type = 'U' )
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 not exists(select 1 from Ls_TabJL where stdm=''''+@stdm+'''')
/************改了这里***************/
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)/*这里错了,int类型不用指定长度 */,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
zjcxc 元老 2003-12-15
  • 打赏
  • 举报
回复
SQL 2000查询分析器
--左连的对象浏览器(没有的话按F8)
--对象项中
--右键调试的存储过程
--调试
--输入参数(必须输入所有的参数,包括默认值/输出参数
--点击执行
--出现一个浮动工具条
--上面有单步执行,断点设置等

按F11是单步执行.

如果要运行到指定行,只需要将光标移动到指定的行,再按Ctrl+F10
houlinghouling 2003-12-12
  • 打赏
  • 举报
回复
我没有跟踪调试!因为我不知道怎么跟踪!初学者,不好意思!^_^!
zcjl :
stdm(试题代码) stlx(试题类型) kzbh(课程编号) yhm(用户名) yhlx(用户类型) sfzq (是否正确)
xscsjl:和zcjl一样
jctxms:
sttx(试题类型) txmc(试题类型名称) dybm(试题所在的表名称)
试题所在表的结构:stdm (试题代码)mc(名称)
以上是用到的表中主要字段!




victorycyz 2003-12-12
  • 打赏
  • 举报
回复
请给出表结构,查询需求。

另,你有没有跟踪调试?

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧