Como traer registros de forma aleatoria

by 24. marzo 2009 17:47

En algunas ocasiones necesitamos traer de forma aleatoria registros, aquí les dejo dos métodos para hacerlo. El primero es compatible desde SQL 2000 a 2008 y el segundo solo con 2005 y 2008 ya que la función TableSample se encuentra en dichas versiones

   1:  USE AdventureWorks 
   2:  GO
   3:   
   4:      SELECT TOP 10 *
   5:      FROM Production.Product  
   6:      ORDER BY NEWID()
   7:      
   8:   
   9:  SELECT  TOP(10) * 
  10:  FROM
  11:  (
  12:   SELECT * FROM Production.Product TABLESAMPLE SYSTEM(25 PERCENT)
  13:   
  14:   ) AS TABLA

Tags: , ,

How To

Comentarios

19/08/2009 10:24:21 #

Hello Guru, what entice you to post an article. This article was extremely interesting, especially since I was searching for thoughts on this subject last Thursday.

payday loan United States

24/08/2009 17:21:47 #

It sounds like you're creating problems yourself by trying to solve this issue instead of looking at why their is a problem in the first place

payday loans United States

Maximiliano Damian Accotto