Home All Groups Group Topic Archive Search About

What's wrong in my Select Statment

Author
4 May 2006 11:45 AM
Islamegy®
I'm try to run this procedure to implement Custom paging so i pass 2
paramters @PageIndex, @PageSize
so if i @PageSize = 5 and PageIndex =2 (0 based index)

then i want to ignore first 10 Rows right??
I wrote the following select statment:

SELECT TOP 5 * FROM EVENTS WHERE NOT EXISTS
(
SELECT TOP 10 * FROM EVENTS T WHERE T.ID = EVENTS.ID
)

I expected it will return 5 rows but it return null!!
What's wrong??

Author
4 May 2006 10:59 AM
ML
Use SET ROWCOUNT n.
http://msdn2.microsoft.com/en-us/library/ms188774.aspx

Don't forget to set rowcount back to 0 at the end of your query.


ML

---
http://milambda.blogspot.com/
Author
4 May 2006 11:30 AM
Will
I think you'd be wanting something like:

SELECT TOP 5 * FROM EVENTS as AlwaysUseAsForAliases WHERE
AlwaysUseAsForAliases.ID NOT IN
(
SELECT TOP 10 T.ID FROM EVENTS T
)
Author
4 May 2006 11:42 AM
Ryan Randall
Hi Islamegy,

Here's an article on paging which you might find helpful...

http://weblogs.sqlteam.com/jeffs/archive/2003/12/22/672.aspx


Show quote
"Islamegy®" wrote:

> I'm try to run this procedure to implement Custom paging so i pass 2
> paramters @PageIndex, @PageSize
> so if i @PageSize = 5 and PageIndex =2 (0 based index)
>
> then i want to ignore first 10 Rows right??
> I wrote the following select statment:
>
> SELECT TOP 5 * FROM EVENTS WHERE NOT EXISTS
> (
> SELECT TOP 10 * FROM EVENTS T WHERE T.ID = EVENTS.ID
> )
>
> I expected it will return 5 rows but it return null!!
> What's wrong??
>
>
>

AddThis Social Bookmark Button