+ Reply to Thread
Results 1 to 8 of 8

Thread: Limiting Query Results?

  1. #1
    Contracted Slave Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    533
    Rep Power
    4

    Limiting Query Results?

    Hello,

    I have 2 SELECT queries made in MS ACCESS.

    The first one counts the number of tickets based on availability and showName.

    Code:
    "SELECT Count(1) AS TicketCount FROM shows INNER JOIN performances ON shows.showID = performances.showID WHERE performances.status="Available" AND shows.showName = "Spooks""
    
    The 2nd query displays the performanceIDs for the shows that are available.

    Code:
    SELECT shows.showName, performances.performanceID FROM shows INNER JOIN performances ON shows.showID = performances.showID WHERE shows.showName="Spooks" AND performances.status="Available""
    
    basically 1st one counts

    and the 2nd one is just a normal query.

    I want to limit the results for the 2nd query to what the user requests. IE. if they select 5 in the previous page i want the query to only return 5 records.

    any ideas?

  2. #2
    Contracted Slave Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    533
    Rep Power
    4

    I found out that by adding 'TOP' it limits the results to what ever number i place it.

    But how do i define the number based on

    Code:
    SELECT TOP 5 showName FROM shows WHERE status = "available"
    
    But the "5" needs to be defined by the user, and it could be any number they select in the combo box in the form

    any ideas?

  3. #3
    Super Sarcasm Mistress mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere's Avatar
    Join Date
    Mar 2008
    Location
    Wide Awake In Dreamland
    Posts
    830
    Rep Power
    8

    is this in an ASP Form or an Access form?
    Quote of the Month:
    INSIGHT: When the going gets tough, the tough get going. The smart left a long time ago.

    Questions to Ponder:
    Are people more violently opposed to fur rather than leather because it's much easier to harass rich women than motorcycle gangs?

    iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
    copyright © 2008 sbenj69

    Sarchasm: The gulf between the author of sarcastic wit and the person who doesn't get it.

  4. #4
    Contracted Slave Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    533
    Rep Power
    4

    Quote Originally Posted by mehere View Post
    is this in an ASP Form or an Access form?
    ASP form

  5. #5
    Super Sarcasm Mistress mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere's Avatar
    Join Date
    Mar 2008
    Location
    Wide Awake In Dreamland
    Posts
    830
    Rep Power
    8

    then your SQL string should look something like this:
    Code:
    strSQL = "SELECT TOP " & request.form("comboboxname") & " showName FROM shows WHERE status = 'available'"
    
    Quote of the Month:
    INSIGHT: When the going gets tough, the tough get going. The smart left a long time ago.

    Questions to Ponder:
    Are people more violently opposed to fur rather than leather because it's much easier to harass rich women than motorcycle gangs?

    iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
    copyright © 2008 sbenj69

    Sarchasm: The gulf between the author of sarcastic wit and the person who doesn't get it.

  6. #6
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Assuming you build the SQL statement in ASP, something like?
    Code:
    strsql = "SELECT TOP " & request.form("noToShow") & " showName FROM shows WHERE status = 'available'"
    
    <edit>What mehere said!</edit>

  7. #7
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    I'm assuming here that by combo box, you mean a <select> element without multiple selections?

  8. #8
    Contracted Slave Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    533
    Rep Power
    4

    Quote Originally Posted by richyrich View Post
    I'm assuming here that by combo box, you mean a <select> element without multiple selections?
    urrrm? yes... i think so

+ Reply to Thread

Similar Threads

  1. Matrix show top 5 results
    By cipriani1984 in forum SQL Server Reporting Services Help
    Replies: 1
    Last Post: December 10th, 2009, 03:06 PM
  2. blank results (href)
    By Rebelle in forum ASP Development
    Replies: 2
    Last Post: October 15th, 2009, 09:04 AM
  3. Procedure Not Returning Expected Results
    By Centurion in forum ASP Development
    Replies: 9
    Last Post: July 8th, 2009, 10:17 AM
  4. Spliced tables, paged results
    By dr_rock in forum SQL Code Samples
    Replies: 0
    Last Post: September 16th, 2008, 03:19 AM
  5. same markup diff results in .Net
    By Shem in forum HTML & CSS Help
    Replies: 4
    Last Post: July 3rd, 2008, 04:45 AM

Bookmarks

Posting Permissions

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

SEO by vBSEO