Showing posts with label resultset. Show all posts
Showing posts with label resultset. Show all posts

Tuesday, March 20, 2012

Paging with Stored Procedures

I have been browsing the newsgroups trying to find a good solution for this
problem.
I have a resultset and I need to show that information in pages. I also need
to have this sorted by a specific column (Date for example)
I found the following solution written by Don Arsenault that works very
well:
/*
The above routines assume that the resultset is ordered by the unique key.
If that's not true, a combination of a sort column and the unique key
can be used. Pass the sort column value as well as the unique key to the
next_page and previous_page procedures. Make sure the table has an index
on the combination of the sort column and the unqiue key.
*/
CREATE PROCEDURE next_page
@.current_page_last_row_key int,
@.current_page_last_row_sort int
AS
--return first page if parameters are null.
IF (@.current_page_last_row_key is null)
SELECT TOP 10 *
FROM my_big_table
ORDER BY sort_column, unique_key
ELSE
SELECT TOP 10 *
FROM my_big_table
WHERE
(sort_column >= @.current_page_last_row_sort)
and (
(sort_column > @.current_page_last_row_sort)
or (unique_key > @.current_page_last_row_key)
)
ORDER BY sort_column, unique_key
CREATE PROCEDURE previous_page
@.current_page_first_row_key int,
@.current_page_first_row_sort int
AS
--return last page if parameters are null.
IF (@.current_page_first_row_sort_key is null)
SELECT *
FROM
(
SELECT TOP 10 *
FROM my_big_table
ORDER BY sort_column DESC, unique_key DESC
) AS Reorder
ORDER BY unique_key
ELSE
SELECT *
FROM
(
SELECT TOP 10 *
FROM my_big_table
WHERE
(sort_column <= @.current_page_last_row_sort)
and (
(sort_column < @.current_page_last_row_sort)
or (unique_key < @.current_page_last_row_key)
)
ORDER BY sort_column DESC, unique_key DESC
) AS Reorder
ORDER BY sort_column, unique_key
That works great when you want to move from one page to the next (or to the
previous one), but I don't know
how I can go to a specific page. For example, go to page 100.
Do you guys know how I can get this?
ThanksYou may also want to refer to www.aspfaq.com/2120 for some ideas.
Anith

Monday, March 12, 2012

Paging on SqlCeResultSet

Hi

I am using SqlCeResult and i want to give paging on that and read in help that you can do paging on ResultSet so . I need code example so that i can understand how to implement this in resultSet.

Thanks & Regards

Vishal

Hi,

I need to implement paging on sqlceresultset. The resultset contains about 60000 records .I want to implement paging and bind it to the grid. I read that it can be done using sqlceresultset, but did not any example anywhere.

Can someone please suggest how to acoomplish this ?

Thanks

|||

There’s no need to “page” ResultSet. RS is a live cursor which loads data only as needed, not all data at once. If bound to DataGrid it would only load visible rows and loads others only as you scroll doing “paging” for you. So just bind your grid to the RS and you're done with "paging".

Friday, March 9, 2012

Paging in MDX

Hi

I am new to mdx.i want to know can we implement paging in mdx query? is there any function in mdx so that i can return resultset based on count.i am using topcount function to return 10 rows.but i want to return result for next top 10 and so on.. in same query. like we do in paging.

Thanks in advance

There are probably ways of doing this, one that comes to mind would be to use a combination of topcount and tail

eg. page1... TopCount( <set>, <expression>, 10)

page2... TopCount( <set>, <expression>, 20).tail(10)