RandomRecords

Returns random IDs (or any column) from SQL Database table, passing number of records to return, column to return, table name and where condition.
Returns list separated by {{$R$}}

Function RandomRecords(Records, Column1, Table1, Where1)
 ' SELECT Top(10) ID FROM Anmars_User.IQNames_Ar Where Order_1=2 ORDER BY NEWID()
 RandomRecords = ""
 fSQL="Select Top(" & Records & ") " & Column1 & " from " & Table1 & " " & Where1 & " order by NEWID()"
 set recF=connection.execute(fSQL)
 Do until recF.Eof
  GGe=GGe & trim(recF(Column1)) & "{{$R$}}"
  recF.MoveNext
 Loop
 RandomRecords = GGe
End Function

Records, Column1, Table1, Where1

Reecs = RandomRecords(10, "ID", "BlogPosts", " where status = 1")

Views 1068 Downloads 347

'Connection', 'Database', 'DB', 'Connection', 'SQL', 'Random', 'column', 'table'

ANmarAmdeen
336
Database Classic ASP
Revisions

v1.0