Page 1 of 1

Sampling data from a table

Posted: Fri 18 Aug 2006 10:33
by alchemy9
Does anyone have any idea how I can sample data from a table,

for example rather than reading every row from the table I would like to select for example 10% of the data evenly throughout the table.

is there a better way than doing

assuming i wanted to read 10% of the data and there were 100 rows...

is there a better way then

if the query was ....select * from atable


1.read row data
2. loop 10 times using next to get the next data
then loop round reading the next value

is there better way, can you can go directly to a certain row in the data set or do you need to loop using next


thanks in advance

Ian

Posted: Fri 18 Aug 2006 13:08
by Jackson
You can use TOP clause in combination with WHERE clause.

Posted: Mon 21 Aug 2006 22:21
by alchemy9
unfortunately a top with a where clause will not give equal data throughout the table. Is tehre not a better way???

Posted: Tue 22 Aug 2006 14:44
by Antaeus
Another way is making a stored procedure that returns result set. It should open a cursor, scroll through it and pick up some of the records to form result set you need.