您的位置:首页 > 其它

[原创]一个考试系统中的存储过程用来生成试卷用的

2008-04-26 20:47 615 查看
CREATEprocpaperbuild@papernamechar(200),@subjectchar(10),@xztint,@xztnint,@tktint,@tktnint,@pdtint,@pdtnint,
@wdtint,@wdtnintas
/*
powerby:liujun
address:衡阳师范学院计算机系0102班
选择题生成部分
*/
declare@bxztint,@kenvarchar(8000)
declare@tempsqlvarchar(8000),@lxztint,@lsndint
set@bxzt=@xzt/2
set@ken=(selecttop1kenlistfromtempkenlistwherepapername=@papername)
set@tempsql='insertintopaper(question1,q_type,right_answer,option1,difficulty)selecttop'+str(@bxzt)+'question1,q_type,right_answer,option1,difficultyfromquestionwhereq_type=''选择题''andsubject='''+@subject+'''andkenin'+@ken+'orderbynewid()'
execute(@tempsql)

set@tempsql='updatepapersetpapername='''+@papername+'''wherepapernameisnull'
execute(@tempsql)

set@lxzt=@xzt-@bxzt
set@lsnd=(selectavg(difficulty)frompaperwherepapername=@papernameandq_type='选择题')

if@lsnd>@xztn
begin
set@tempsql='insertintopaper(question1,q_type,right_answer,option1,difficulty)selecttop'+str(@lxzt)+'question1,q_type,right_answer,option1,difficultyfromquestionwhereq_type=''选择题''andsubject='''+@subject+'''anddifficulty<'''+str(@lsnd)+'''andkenin'+@ken+'andquestion1notin(selectquestion1frompaperwhereq_type=''选择题''andpapername='''+@papername+''')orderbynewid()'
execute(@tempsql)
end
else
begin
set@tempsql='insertintopaper(question1,q_type,right_answer,option1,difficulty)selecttop'+str(@lxzt)+'question1,q_type,right_answer,option1,difficultyfromquestionwhereq_type=''选择题''andsubject='''+@subject+'''anddifficulty>'''+str(@lsnd)+'''andkenin'+@ken+'andquestion1notin(selectquestion1frompaperwhereq_type=''选择题''andpapername='''+@papername+''')orderbynewid()'
execute(@tempsql)
end
set@tempsql='updatepapersetpapername='''+@papername+'''wherepapernameisnull'
execute(@tempsql)
/*
填空题生成部分
*/
declare@btktint,@ltktint
set@btkt=@tkt/2

set@tempsql='insertintopaper(question1,q_type,right_answer,option1,difficulty)selecttop'+str(@btkt)+'question1,q_type,right_answer,option1,difficultyfromquestionwhereq_type=''填空题''andsubject='''+@subject+'''andkenin'+@ken+'orderbynewid()'
execute(@tempsql)

set@tempsql='updatepapersetpapername='''+@papername+'''wherepapernameisnull'
execute(@tempsql)

set@ltkt=@tkt-@btkt
set@lsnd=(selectavg(difficulty)frompaperwherepapername=@papernameandq_type='填空题')

if@lsnd>@tktn
begin
set@tempsql='insertintopaper(question1,q_type,right_answer,option1,difficulty)selecttop'+str(@ltkt)+'question1,q_type,right_answer,option1,difficultyfromquestionwhereq_type=''填空题''andsubject='''+@subject+'''anddifficulty<'''+str(@lsnd)+'''andkenin'+@ken+'andquestion1notin(selectquestion1frompaperwhereq_type=''填空题'' andpapername='''+@papername+''')orderbynewid()'
execute(@tempsql)
end
else
begin
set@tempsql='insertintopaper(question1,q_type,right_answer,option1,difficulty)selecttop'+str(@ltkt)+'question1,q_type,right_answer,option1,difficultyfromquestionwhereq_type=''填空题''andsubject='''+@subject+'''anddifficulty>'''+str(@lsnd)+'''andkenin'+@ken+'andquestion1notin(selectquestion1frompaperwhereq_type=''填空题''andpapername='''+@papername+''')orderbynewid()'1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: