I have a table that currently has 29 rows.
I have a report that is trying to list the contents of the table in two columns. I want them to come out with equal number of rows in each, with the first column having one more item if there are an odd number of items. I am trying to develop a method that will work if the table has anywhere from 1 to 200 rows.
I tried this....
To select the records for column A:
SELECT TOP 50 Percent <fields> Order By DisplayOrder;
To select the records for column B:
SELECT TOP 50 Percent <fields> Order By DisplayOrder DESC;
The problem is I am getting (in this case) the 15th row included in both queries.
I tried lowering the percent in the second query to 49, but I still get 15 records returned (the last 15 records).
Is there a good way to get the first half of a table, and the last half of a table, and be sure not to include the middle row in both result sets, and be sure not to leave out a row?
I have a report that is trying to list the contents of the table in two columns. I want them to come out with equal number of rows in each, with the first column having one more item if there are an odd number of items. I am trying to develop a method that will work if the table has anywhere from 1 to 200 rows.
I tried this....
To select the records for column A:
SELECT TOP 50 Percent <fields> Order By DisplayOrder;
To select the records for column B:
SELECT TOP 50 Percent <fields> Order By DisplayOrder DESC;
The problem is I am getting (in this case) the 15th row included in both queries.
I tried lowering the percent in the second query to 49, but I still get 15 records returned (the last 15 records).
Is there a good way to get the first half of a table, and the last half of a table, and be sure not to include the middle row in both result sets, and be sure not to leave out a row?