Obtener registro aleatorio en SQL Server
SQL Server
- Por Programador ASP clásico /
- 03/06/2014 @ 09:49:01 /
- 1008 visitas
Esta es la forma más sencilla de obtener un registro aleatorio a través de SQL Server, el cual puede ser utilizado en nuetras aplicaciones ASP clásico:
SELECT TOP 1 id_cliente
FROM clientes
ORDER BY NewID()
Si estamos utilizando como motor de base de datos Access, no es posible usar la función NewID() de sql server por lo que debemos utilizar el siguiente código para ASP clásico:
<%
Randomize()
intRandomNumber = Int (1000*Rnd)+1
strSQL = _
"SELECT TOP 3 TableID, Field1, Rnd(" & -1 * (intRandomNumber) & "*TableID)" & _
"FROM Table1 " & _
"ORDER BY 3"
Set objRS = objConn.Execute(strSQL)
%>
tags: