Results 1 to 8 of 8

Thread: MAx records

  1. #1
    Join Date
    Jan 2009
    Posts
    124

    Unanswered: MAx records

    I want to limit my client to creating ten records. Once they have created ten records I will hide the insert form.

    I tried using count() and limiting count but that dosen't work. CAn anyone point e in the right direction?

    Thanks

    Nick

  2. #2
    Join Date
    Jan 2009
    Posts
    124
    I should add that if the have ten record thenI would let them delete ont if they wanted to add another.

  3. #3
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by oldnickj View Post
    I should add that if the have ten record then I would let them delete one if they wanted to add another.
    by un-hiding the delete form?

    the mere fact that you are implementing some logic (hiding) in the application code suggests that you could easily handle the 10-row limit there as well

    just do a SELECT COUNT(*) before deciding whether to hide or show the insert form
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  4. #4
    Join Date
    Jan 2009
    Posts
    124
    I've over simplified what I'm trying to do.
    I wan the query to return nothing if the count is greater then 10 OR only return results if there are ten or more records.

    This dosn't work of course:

    SELECT COUNT(*) AS C
    FROM image_img
    WHERE C>10

    Nick

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by oldnickj View Post
    I wan the query to return nothing if the count is greater then 10 OR only return results if there are ten or more records.
    but those two options are diammetrically opposite to each other

    let's try the first one
    Code:
    SELECT CASE WHEN COUNT(*) > 10
                THEN NULL
                ELSE COUNT(*) END AS thecount   
      FROM image_img
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  6. #6
    Join Date
    Jan 2009
    Posts
    124
    The recordset still has one record "NULL". What I need to an empty recordset if they have 10 records, If they have fewer than ten then return *


    SELECT CASE WHEN COUNT(*) >10
    THEN NULL
    ELSE COUNT(*) END AS thecount
    FROM image_img

    WHERE artist_img=101


    Thanks

    Nick

  7. #7
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by oldnickj View Post
    What I need to an empty recordset if they have 10 records, If they have fewer than ten then return *
    Code:
    SELECT *
      FROM image_img
     WHERE artist_img = 101 
       AND 10 > 
           ( SELECT COUNT(*) 
               FROM image_img
              WHERE artist_img = 101 )
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  8. #8
    Join Date
    Jan 2009
    Posts
    124
    Beautiful! Thanks very much

Posting Permissions

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