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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-01-28 : 08:42:18
|
| Russel writes "Hi,These are some questions that I would want a solution for1) a cretain row in a table ie. if I want the 5th row the 5th row must come up.2) odd rows in a table3) even rows in a table4) row number along with the each record detailseg ....1 ..........................2 ..........................3 ..........................Kindly address these. I would require a select statement and not a store procedure for the same results" |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-01-28 : 09:25:57
|
| If you search SQL Team for "row number" you'll get a bunch of articles, this is the first:http://www.sqlteam.com/item.asp?ItemID=1491Also search for "TOP" and check graz's article "What's After Top?".For odd numbered rows, you can use Modulo (% in SQL Server) to mod the row number by 2:SELECT * FROM myTable WHERE row_number % 2 = 0 --gets even rowsSELECT * FROM myTable WHERE row_number % 2 = 1 --gets odd rowsBe aware that there is no built-in row number, you have to calculate it. Also, it's arbitrary, and depends entirely on how you ORDER BY your SELECT statement. If you don't have an ORDER BY clause you will not get consistent results. |
 |
|
|
|
|
|