Results 1 to 8 of 8

Thread: Get both COUNT and LIMITed resultset

Threaded View

  1. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Get both COUNT and LIMITed resultset

    Ok - then I'm guessing the COUNT is needed so that the LIMIT can be determined for the final resultset. And it's probably not something as simply as 50% or 25% (which TOP 50 PERCENT is allowed in MS SQL at any rate).

    Then I agree with what Si said - build a temp table. It can be just the primary key's of the rows to get so that the complex WHERE clause only occurs in the building of the temp table.

    Then the LIMIT'd 2nd resultset comes FROM the primary key's of the temp table - which should make the second fetch much faster.
    Last edited by szlamany; Apr 14th, 2008 at 06:37 AM.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width