Sampling data from a table

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
alchemy9
Posts: 5
Joined: Wed 01 Feb 2006 06:39

Sampling data from a table

Post by alchemy9 » Fri 18 Aug 2006 10:33

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

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Fri 18 Aug 2006 13:08

You can use TOP clause in combination with WHERE clause.

alchemy9
Posts: 5
Joined: Wed 01 Feb 2006 06:39

Post by alchemy9 » Mon 21 Aug 2006 22:21

unfortunately a top with a where clause will not give equal data throughout the table. Is tehre not a better way???

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Tue 22 Aug 2006 14:44

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.

Post Reply