Here is one solution for Paging queries, perhaps it will give you a clue.
Arnie Rowland, Ph.D.
Most good judgment comes from experience.
Most experience comes from bad judgment.
top yourself.
- H. Norman Schwarzkopf
<info@programmersheaven.com> wrote in message
news:1164237624.689854.37340@j44g2000cwa.googlegroups.com...
> Hi
>
> Using SQL Server 2005.
>
> I have a fairly complex query that I apply paging to using the With
> statement like
>
> (dummy sample taken from
>
http://davidhayden.com/blog/dave/archive/2005/12/30/2652.aspx)
>
> WITH LogEntries AS (
> SELECT ROW_NUMBER() OVER (ORDER BY Date DESC)AS Row, Date, Description
> FROM LOG WHERE xxxxxxxxxxxxx)
>
> SELECT Date, Description
> FROM LogEntries
> WHERE Row between @RowStart and @RowEnd
>
>
> That's fine.
>
> but to be able to figure out the number of pages, I also need to know
> the total # of rows in LogEntries above.
>
> like
>
> SELECT Count(*) FROM LogEntries
>
> But the scope of the "LogEntries" result is only one query and I cant
> apply two SELECT statements against that result.
>
> So, are there any better way than having to run the same query twice?
> like
>
>
> SELECT Count(*) FROM LOG WHERE xxxxxxxxxxxxx
>
> Do I have to use SQLCLR to fix this? like doing the query once in
> SQLCLR and output two recordsets from the SQLCLR procedure?
>