Abort count if given number exceeded in SQL query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TimSki
    New Member
    • Jan 2008
    • 83

    Abort count if given number exceeded in SQL query

    This is probably a dumb question...

    but,

    I have a large table 10M rows. I want to do a typical sql count BUT i want to abort the count (and return me the count so far) if it exceeds a certain number

    kind of...

    select count(id)
    from bigtable
    where maxcount cannot exceed 200

    any ideas ?
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Code:
    select top 200 .....?

    Comment

    • TimSki
      New Member
      • Jan 2008
      • 83

      #3
      thanks but that wont work because i don't want to bring back the records

      Comment

      • ck9663
        Recognized Expert Specialist
        • Jun 2007
        • 2878

        #4
        Do you just want to know if the number of records in a table is greater than X? If that's the case, use this view instead.

        Good Luck!!!

        ~~ CK

        Comment

        • Sandeep M

          #5
          will it solve?

          select count(id)
          from bigtable
          where.....
          group by <field>
          having count(id)<@limi t

          Comment

          Working...