急需:在存储过程中如何创建动态临时表,怎样来查询这个临时表(100)

急需:在存储过程中如何创建动态临时表,怎样来查询这个临时表(100) - 故障解答 - 电脑教程网

急需:在存储过程中如何创建动态临时表,怎样来查询这个临时表(100)

日期:2007-10-24   荐:
急需:在存储过程中如何创建动态临时表,怎样来查询这个临时表(100)例如:通过查询题库根据传过来的知识点建立一个临时表(要求:有该知识点的临时表就不需要建表,如果没有就建立新的临时表)create PROCEDURE test@point int --知识点asif not exists(select name from tempdb..sysobjects where name='##temp_choices' str(@point)) --判断是否存在临时该知识点表begin??????????end . . . . .select 刚才建的临时表的字段名 from ???????? where 条件(问号是我的问题)不知道可以用我这格式写么?如果可以,该怎么写?如果不可以,在存储过程中怎样完成这功能?谢谢可以,全局的临时表可以用你的方法判断.注意多用户调用时的冲突问题to邹建老师:那怎么写呢?但对有的临时表也不能删除,如果删除的话,那就相当于每次都要建临时表了最好是举例说明要求,这样才能准确知道那种方法适合,以及如何处理我建議樓主舉例來說明此問題题库在没有介入知识点是,从题库抽出道题存储过程是这样写的:create PROCEDURE test@stunum nvarchar(10), --学生学号@totalnum int, --题目总量@seriNum int --抽题序号 (需需增加知识点参数,选择属于某知识点的题)AS declare @rownum int --行号declare @choiceId int --id号if not exists(select name from tempdb..sysobjects where name='##temp_choice') --判断是否存在临时选择题表begin select identity(int,1,1) as rownum,* into tempdb..##temp_choice from examdata..choicesendset @rownum=ceiling(rand()*@totalnum) --取整while @rownum=0begin set @rownum=ceiling(rand()*@totalnum) --随机生成非零行号endDECLARE choiceId_cursor CURSOR FOR --声明一个游标,取出这个题目的id号SELECT iChoiceIdFROM tempdb..##temp_choice where rownum=@rownumOPEN choiceId_cursorfetch choiceId_cursor into @choiceIdclose choiceId_cursorDEALLOCATE choiceId_cursorif not exists(select cStuNum,iChoiceId from examdata..choicesAnswer where cStuNum=@stunum and iChoiceId=@choiceId) --如果没有抽取改题目begin insert into examdata..choicesAnswer(cStuNum,iChoiceId,iSeriNum) values(@stunum,@choiceId,@seriNum) select * from tempdb..##temp_choice where rownum=@rownumendelse --已经抽取,重新选择新的题目begin set @rownum=ceiling(rand()*@totalnum) while @rownum=0 or exists(select cStuNum,iChoiceId from examdata..choicesAnswer where cStuNum=@stunum and iChoiceId=@choiceId) begin set @rownum=ceiling(rand()*@totalnum) --随机生成非零行号 DECLARE choiceId_cursor CURSOR FOR --声明一个游标,取出这个题目的id号 SELECT iChoiceId FROM tempdb..##temp_choice where rownum=@rownum OPEN choiceId_cursor fetch choiceId_cursor into @choiceId close choiceId_cursor DEALLOCATE choiceId_cursor end insert into examdata..choicesAnswer(cStuNum,iChoiceId,iSeriNum) values(@stunum,@choiceId,@seriNum) select * from tempdb..##temp_choice where rownum=@rownum end--这里我想使用iChoiceId--select * from tempdb..##temp_choice where rownum=@rownumGOSET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON GO现在我是对每个题目加了知识点号以知识点来随机抽出一道题目那它的存储过程应该怎么写直接举例说明要求吧to邹建:您好! 我就是给你发短消息hdh006.我的问题就是关于考试系统建了了三个表的随机调出相关知识点的题目。我现在还没有解决这个问题。想你帮我一把谢谢,您对我这个问题的多次关注。
标签: