0
我需要一些关于存储过程的帮助。它包含一个运行Select
查询的循环。如果它循环三次,我得到的结果是3个表。如何将结果组合为一个表格?将多个查询的结果作为SQL Server存储过程中的一个结果结合起来
的过程如下:
CREATE PROCEDURE [dbo].[spGetRndQuestions]
@ExamCode Nvarchar(60)
AS
BEGIN
Declare @NosQues Int, @Catgry nvarchar(50)
DECLARE CategCursor CURSOR FOR
(Select Category From tblExamDetail Where ExamCode = @ExamCode)
OPEN CategCursor
FETCH NEXT FROM CategCursor INTO @Catgry
WHILE @@FETCH_STATUS = 0
BEGIN
SET @NosQues = (Select NoOfQues from tblExamDetail Where [email protected] AND [email protected])
SELECT TOP(@NosQues) QM.QuestionID, QM.QuestionDesc, QM.QuestionMarks, QM.Answer1, QM.Answer2, QM.Answer3, QM.Answer4 FROM tblQuestionMaster QM
INNER JOIN tblExamMaster EM ON QM.Dept = EM.Dept AND QM.Location = EM.Location AND QM.QuesModule = EM.ExamModule
Where [email protected] AND QM.Category [email protected]
Order by NEWID()
/*SELECT TOP (@NosQues) QuestionID,QuestionDesc,Answer1,Answer2,Answer3,Answer4,QuestionMarks from [dbo].[tblQuestionMaster] Where [email protected] AND
Order by NEWID() */
FETCH NEXT FROM CategCursor INTO @Catgry
END
CLOSE CategCursor
DEALLOCATE CategCursor
END
谢谢你的帮助是真正的赞赏。
非常感谢哈姆雷特,这很有魅力。非常感谢您的帮助。 –