ASP SQL and Access database randomly take 10 records of code NEWID () _ Application Tips

Source: Internet
Author: User
Tags access database
Mssql:select top * to [table] order by NEWID ()

ACCESS:

Copy Code code as follows:

' To use Rs.move.
' If you randomly take 10 strips
n = 10
' first to determine whether the total number of records is less than 10, if less than 10, then how many how much to take if n>10 Rs.recordcount then N=rs.recordcount
Dim rannum
For i = 1 to n
Randomize ()
rannum = Int (rs.recordcount*rnd) +1 ' produces a random number
Rs. Move Rannum ' moves a cursor to a random number position
Response.Write I & "-" & RS ("title") & "<br/>" ' Output
Rs. Move-rannum
Next
'......
That's it, of course, so it's possible to get a duplicate record, then the resulting random number of the sentence can be changed, declaring a variable to hold the random number has been produced, in the generation of new random to determine whether has been produced, if produced by the regeneration is, this is relatively simple, With InStr and so on can be done ~ ~

The idea is this, others try it yourself. One way to do this is to generate only a random number and then read the N records next to the random number. Of course to write a good judgment, the random number is less than the total number of records-to read the number of records.

Copy Code code as follows:

'......
Dim n,rannum
n = 10
Randomize ()
Rannum = Rs.recordcount-n
If Rannum<1 then Rannum=1
rannum = Int (rannum*rnd) +1

Rs. Move Rannum
For I=1 to 10
Response.Write I & "-" & RS ("title") & "<br/>" ' Output
Rs. MoveNext ' Read down next to
Next
'......
It is recommended that you write a simple function to produce and judge a random number that is not repeated.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.