Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
qman
Constraint Violating Yak Guru
442 Posts |
Posted - 2007-10-25 : 15:58:44
|
| I need to run a query that will output every 25th row in a table. For example, if source table A has 500 rows, the result should show 20 rows. |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-10-25 : 16:40:14
|
| Get the result into a temp table or table variable which has an identity column and do a select from the table where mod/25=0.Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-26 : 02:59:03
|
quote: Originally posted by dinakar Get the result into a temp table or table variable which has an identity column and do a select from the table where mod/25=0. id_col%25=0Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/
MadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-10-26 : 03:01:34
|
or use row_number() KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-10-26 : 03:07:55
|
quote: Originally posted by qman I need to run a query that will output every 25th row in a table. For example, if source table A has 500 rows, the result should show 20 rows.
Forget to note that you posted in sql server 2005 forumSelect columns from(select row_number() over (order by col) as n, columns from table) as twhere n%25=0MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|