|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
total number of items selectedIs it possible to perform a select statement with a top 1000 and still count
how many records meet the criteria without having to select without the top ? Any help would be appreciated. I am looking to achieve a result where I can inform the user of the real total number of records that meet the selection criteria in total. I'm not sure understood your requirements
Could it be? SELECT TOP 50 COUNT(*)AS cnt,CustomerId FROM Orders GROUP BY CustomerId Show quoteHide quote "Tlink" <c***@melbournehosting.com> wrote in message news:ew3aa7VsGHA.4596@TK2MSFTNGP04.phx.gbl... > Is it possible to perform a select statement with a top 1000 and still > count how many records meet the criteria without having to select without > the top ? Any help would be appreciated. > > I am looking to achieve a result where I can inform the user of the real > total number of records that meet the selection criteria in total. > Uri Dimant wrote:
> I'm not sure understood your requirements I think he wants to get a count of the total number of rows that wouldhave been returned by the query if the query didn't have the "TOP x" clause, and at the same time limiting the rows returned to x rows. hi,
use @@rowcount e.g select top 5 *,@@rowcount from tablea assume tablea contains only 3 rows 1 xxx 2 aaa 3 bbb running the above sql reurnts the reslut as 1 xxx 3 2 aaa 3 3 bbb 3 thanks Show quoteHide quote "Tlink" <c***@melbournehosting.com> wrote in message news:ew3aa7VsGHA.4596@TK2MSFTNGP04.phx.gbl... > Is it possible to perform a select statement with a top 1000 and still > count how many records meet the criteria without having to select without > the top ? Any help would be appreciated. > > I am looking to achieve a result where I can inform the user of the real > total number of records that meet the selection criteria in total. > vinu wrote:
Show quoteHide quote > select top 5 *,@@rowcount from tablea I think the OP wants it to return the following if there were 10 rows> > assume tablea contains only 3 rows > > 1 xxx > 2 aaa > 3 bbb > > running the above sql reurnts the reslut as > > > 1 xxx 3 > 2 aaa 3 > 3 bbb 3 in tablea: 1 xxx 10 2 aaa 10 3 bbb 10 4 ccc 10 5 ddd 10 Don't think that's possible using a single query. Tlink wrote:
> Is it possible to perform a select statement with a top 1000 and still count I think you would need to put the full result set into a temp table (or> how many records meet the criteria without having to select without the top > ? Any help would be appreciated. > > I am looking to achieve a result where I can inform the user of the real > total number of records that meet the selection criteria in total. CTE in SQL Server 2005) and then do your "TOP x" and COUNT(*) from it. Not good if you are expecting a large result set. Alternatively you would have to do a separate query to count the full number of rows.
SQL Join question - getting most recent value in a history table
Select problem Msg. 156 Indexing a view -- help! datetime between problem how to get charindex of char between numbers? suggestions for improving sortable, paging, filterable, fulltext non-dynamic query error message - what to do? unable to rollback transaction help! Pros and Cons of Using GUIDs for Primary Keys What happens to rows when RETURN is invoked? |
|||||||||||||||||||||||