Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am run this sp it will not return value.

SQL
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


please help me i am using NewID method.
Posted
Comments
Mehdy Moini 18-Oct-13 11:50am    
Well, your where clauses may remove rows from your result!
RedDk 18-Oct-13 13:09pm    
Show me six rows of data from table named "tbl_TestPaper" and I'll help you.
coded007 22-Oct-13 8:17am    
Have you checked Test paper code exists in the table

There's all sorts of reasons for #temp to be empty. A start would be to know if there's any inserts happening.

I'd break this down and run bits of it to see what they return to work out where it's not doing what you want. OR add some logging code so it tells you what it did and did not do.
 
Share this answer
 
See in this don't use drop table #Temp because you are selecting record from Temp table.

In MySQL, temporary tables are dropped automatically when a database connection is closed. If you plan on leaving your connection open after the stored procedure, your temp table will exist on disk until that connection is closed. The performance implications depend on many factors, such as how you have configured temporary table storage on your server, how much data is in the table, etc.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900