Considerando que pueden haber identificadores que no corresponden ya a ningún registro, este stored procedure devuelve un registro al azar de una tabla
CREATE PROCEDURE getRandomRecord AS SET NOCOUNT ON DECLARE @id int // del registro seleccionado DECLARE @max int // total de registros DECLARE @rnd float // número aleatorio DECLARE @sel int // número aleatorio entero // Averiguamos cuantos registros hay SELECT @max = count(*) FROM t_TABLE // Obtenemos un aleatorio enterio entre 0 y @max SET @rnd = @max * DatePart(ms, GetDate()) / 1000 SET @sel = cast(@rnd as int) // Obtenemos el identificador del registro en esa posición DECLARE crs SCROLL CURSOR FOR SELECT idRecord FROM t_TABLE OPEN crs FETCH ABSOLUTE @sel FROM crs INTO @id CLOSE crs DEALLOCATE crs // Selecionamos dicho registro SELECT * FROM t_TABLE WHERE idRecord = @id GO
ConnectionString = "DRIVER=SQL Server;SERVER=localhost;DATABASE=MasterDB;Address=127.0.0.1,1433;Trusted_Connection=Yes;" set conn = Server.CreateObject("adodb.connection") conn.open ct_ConnectionString conn.execute "INSERT ..." set rs = Server.CreateObject("adodb.recordset") rs.Open "SELECT ...", conn do until rs.eof rs.MoveNext: loop rs.Close set rs = Nothing conn.close set conn = Nothing