pucca
April 18, 2006, 10:59am
1
I want to random select 5 records from my database… I got this code,
Code:
[LEFT]SELECT Top 5 * FROM comptbl ORDER BY NewID()[/LEFT]
but its gives me an error saying “[FONT=Arial][SIZE=2]Undefined function 'NewID() in expression.”
What must I do? The site is done in asp… with a access database - if that helps?..
thanks for the help! [/SIZE][/FONT]:puzzled:
955
April 18, 2006, 11:52am
2
Please don’t double post. Thanks.
I’ve never seen syntax like that in a SQL query…
teiz77
April 19, 2006, 7:16am
3
pucca:
I want to random select 5 records from my database… I got this code,
Code:
[LEFT]SELECT Top 5 * FROM comptbl ORDER BY NewID()[/LEFT]
but its gives me an error saying “[FONT=Arial][SIZE=2]Undefined function 'NewID() in expression.”
What must I do? The site is done in asp… with a access database - if that helps?..
thanks for the help! [/SIZE][/FONT]
NewId() only works on SQL server…
Try something like this:
<%
Randomize()
randNum = (CInt(1000 * Rnd) + 1) * -1
set conn = CreateObject("ADODB.Connection")
sql = "SELECT TOP 5 cols," & _
"r = Rnd(" & randNum & ")" & _
"FROM TableName " & _
"ORDER BY r"
set rs = conn.execute(sql)
response.write rs(0)
' ...
rs.close: set rs = nothing
conn.close: set conn = nothing
%>