April 1, 2002 at 11:28 am
Hi,
I am trying to select rows randomly from a table. TOP n [percent] only gives the top %age of rows. is there any way i can do it using T-SQL?
April 1, 2002 at 2:29 pm
April 1, 2002 at 3:21 pm
Not really fancy but you could try something like this
DECLARE @var AS INT
SELECT @var = RAND( (DATEPART(mm, GETDATE()) * 100000 )
+ (DATEPART(ss, GETDATE()) * 1000 )
+ DATEPART(ms, GETDATE()) )
/* You will need to decide how Rand can best help you as in this way it may not be a large enough number. This should give you a blueprint though to what may help you. */
SELECT columnlist FROM tblX outX WHERE (@var-1) = (SELECT COUNT(*) FROM tblX inX WHERE inX.uniid > outX.uniid
"Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply