473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How to store the records returned by a query using while loop in SQL server 2000

20
I want to generate random questions from a table in sql server
i would like to use stored procedure whose input parameter will be integer that comes from web page(.aspx).

Below is the query to generate 10 random questions.
can i store the records in a temp table or array in sql server (i doubt if it is available) from where i can display them on a .aspx page using sqldata adapter in ASP.NET 2.0(VS 2005). Is there a better way to do?

Any guidance will be of great help to me
thanx

Expand|Select|Wrap|Line Numbers
  1. DECLARE @intFlag INT
  2.  
  3. DECLARE @random INT
  4. DECLARE @upper INT
  5. DECLARE @lower INT
  6.  
  7. SET @intFlag = 1
  8.  
  9.  
  10. set @lower=1
  11. set @upper=100
  12.  
  13. WHILE (@intFlag <=10)
  14.  
  15. BEGIN
  16. select @random=Round(((@upper-@lower-1))*RAND()+@lower,0)
  17.  
  18.  
  19. PRINT @random
  20.  
  21. select * from science where ques_no=@random
  22.  
  23. SET @intFlag = @intFlag + 1
  24.  
  25. END
  26.  
  27. GO
  28.  
May 12 '13 #1
4 1699
weaknessforcats
9,208 Expert Mod 8TB
I believe you can declare a cursor for your SELECT. The query result is paced in the cursor, which is a table, and you can then FETCH from this cursor to see the rows.

BTW: SQL is not my strong suit but I thought I'd try to help.
May 12 '13 #2
Rabbit
12,516 Expert Mod 8TB
You should just use a select statement and order by the rand. Don't forget to seed it with a variable factor, such as time, in combination with a unique id, such as your question number.
May 12 '13 #3
ck9663
2,878 Expert 2GB
You can do a select statement and directly save the result to another table using the INTO clause.

With respect to the randomization part, you can read this and this...

Watch out the RAND() function as it will return the same thing within a single statement.

Happy Coding!!!


~~ CK
May 13 '13 #4
shanboy
20
Thanks everyone for replying

@weaknessforcats

i am using stored procedure(SP).In that i have used 'insert into' in a temp table and retriving the records from there.
i would like to use these records as output parameter in the SP to display them in a aspx page.As far as i know we should give the data type of out parameter .
what will be the data type of these records table or any other type.
May 19 '13 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Yves Touze | last post by:
Hi All, I'm trying to migrate from SQL Server 7.0 to SQL Server 2000. I've got some ASP page which call VB components that retrieve shaped recordsets from SQL Server using the MSDATASHAPE...
9
by: wiredog | last post by:
I am struggling rewriting my query from MS Access' IIF, Then to SQL Servers TSQL language. I am hoping some one can give me some guidance. I believe I have the first portion of the query correct...
1
by: elpico | last post by:
Hi there, I've only recently started a project using sql server 2000 for the first time. One of the considerations we have to take is that we need to continuously age/purge data from a couple of...
10
by: B Moor | last post by:
Host PC: Win SBS 2003 with 2.6 GHz processor and 1GB RAM SQL Server 2000 sp3 (or latest).MS Office 2k3 I have the access 2k3 front end running on server (this may get changed) and all was well...
2
by: ILCSP | last post by:
Hello, I'm in the process of changing our 'normal' Access 2000 update queries to Update Pass Through Queries. We have a SQL server 2000 database and we're using an Access 2000 database as our...
1
by: mrclash | last post by:
Hello, I have a Database in a SQL Server 2000 where I have different users tables with equal fields like this: id (int) email (varchar) name (varchar) address (varchar) joinedon (datetime)
0
by: imranabdulaziz | last post by:
Dear All, I am basically new as far as SQl server 2005 concern. I want to try out reporting services provided by sql server 2005. That is make report using sql server 2005 and call that report...
2
by: hisham123 | last post by:
I need to Format the number 123.745817 to 123.75 by using Sql Server 2000 Query
1
by: RubyRed | last post by:
Using SQL Server 2000. Basically, I am trying to calculate each minute of an employee scheduled time during their work shift. In the table below shows only the times that the shift begin...
3
by: shobhitguptait | last post by:
How to Run C#.NET Windows App on N/W with centralized DB using SQL SERVER 2000 Hello All...i m really grate full to c such a website where developers try to help people like us who face problems...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.