alter PROCEDURE [USP_GetListOfQuestion] -- Add the parameters for the stored procedure here @TestPaperCode varchar AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; DECLARE @RowCount INT; Select @RowCount = Count(*) from tbl_TestPaper where TestPaperCode = @TestPaperCode Create table #Temp ( QuestionId bigint ) DECLARE @intFlag INT SET @intFlag = 1 WHILE (@intFlag <=@RowCount) BEGIN --Change DECLARE @NoOfQst INT; select @NoOfQst = max(NoOfQuestions ) from (SELECT Row_Number() OVER (ORDER BY TestPaperId) RoNo,* from tbl_TestPaper where TestPaperCode = @TestPaperCode) X where RoNo=@intFlag Insert Into #Temp(QuestionId) Select Questionid from ( Select top(@NoOfQst) Questionid as 'Questionid' from dbo.tbl_Questions a inner join (SELECT Row_Number() OVER (ORDER BY TestPaperId) RoNo,* from tbl_TestPaper where TestPaperCode = @TestPaperCode) b on a.CategoryId=b.CategoryId and a.Marks=b.Marks Where RoNo=@intFlag ORDER BY NEWID())Y --Change print @intFlag SET @intFlag = @intFlag + 1 END -- Insert statements for procedure here Select * from #Temp drop table #Temp END GO
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)