Legacy ASP, SQL Server, Paging Stored Procedure - resend

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Re: Re: Legacy ASP, SQL Server, Paging Stored Procedure - resend

    I'm not sure if this made it so I'm resending it (with correction):

    This is the best I could come up with. The only other
    solutions I could think of involved cursors or dynamic
    sql, both of which I try to avoid.

    create procedure getrecords (
    @recsrequested tinyint) AS
    set nocount on

    set rowcount @recsrequested
    select personid into #temp from pimples order by personid

    set rowcount 0
    select distinct personid into #temp2 from #temp

    select t1.personid,t1.fname,t1.lname,t2.location
    from persons t1 inner join #temp2 t3
    on t1.personid = t3.personid inner join pimples t2
    on t1.personid = t2.personid

    drop table #temp
    drop table #temp2


    HTH,
    Bob Barrows


    aj wrote:
    > Bob,
    > sorry, my mistake it's 5. what I meant was...
    > (1x3)+(1X2)
    >
    > Anyways,
    >
    > That is the result set....
    >
    > PersonID FName LName Location
    > 2 Bart P Nose
    > 2 Bart P Chin
    > 2 Bart P Butt
    > 3 Bob B Leg
    > 3 Bob B Arm
    >
    > I want two records...
    > dbconn.execute("getRecords 2")
    >
    > The getRecords proc will return the two records but I
    > really want it to return 3 records because the third
    > record is still PersonID and I want the proc to grab that
    > record then stop.
    >
    > Here is what I want when I ask for 2 records...
    > PersonID FName LName Location
    > 2 Bart P Nose
    > 2 Bart P Chin
    > 2 Bart P Butt
    >
    > sorry for the confusion,
    > aj
    >
    >> -----Original Message-----
    >>
    >>> -----Original Message-----
    >>> sure....
    >>>
    >>> -------person-------- -------pimple--------
    >>> PersonID FName LName Location PersonID
    >>> 2 Bart P Nose 2
    >>> 3 Bob B Chin 2
    >>> Butt 2
    >>> Leg 3
    >>> Arm 3
    >>>
    >>>
    >>> the query...
    >>> select * from person inner join pimple on
    >>> person.personid=pimple.pimpleid order by personID
    >>>
    >>> Which will return 2X5=10 rows
    >>
    >> Why do you think this query will return 10 rows? it should
    >> only return 5 rows which will look like this (once you get
    >> rid of the * and list the columns you want it to return):
    >>
    >> select t1.PersonID,t1.FName,t1.LName,t2.Location
    >> from person t1 inner join pimple t2 on
    >> t1.personid=t2.pimpleid order by t1.personID
    >>
    >> PersonID FName LName Location
    >> 2 Bart P Nose
    >> 2 Bart P Chin
    >> 2 Bart P Butt
    >> 3 Bob B Leg
    >> 3 Bob B Arm
    >>
    >>>
    >>> What I want the stored proc to do is know when to return
    >>> records based on the number of records I pass it, plus
    >>> more records if the "cursor" is still on an existing
    >>> personID. Once it goes to a new PersonID, stop.
    >>>
    >> Again, how is what you want different from what this join
    >> query returns already (see above)? Show me what you want
    >> (in tabular form) instead of describing it.
    >>
    >> Bob Barrows
    >> .


    Bob Barrows Guest

  2. Similar Questions and Discussions

    1. SQL Server Stored Procedure Authentication
      Hello, I am tyring to add a level of security to my application with using a username and password to authenticate to the database with when...
    2. RecordCount with Stored Procedure in SQL Server
      Hi everyone, I have noticed that if I used a stored procedure to populate an ADO RecordSet it only returns a .RecordCount property if that stored...
    3. Inserting Full Stops into SQL Server 2000 using ASP and stored procedure
      Hi All, I am attempting to use a standard HTML form to pass a parameter to an ASP stored procedure, which searches a database for customer...
    4. Deploying a Db2 PL stored procedure on the production server
      We are setting up a DB2 (UDB 8.1) environment. I need some guidance to set up the development and deployment process. Lets say I have a...
    5. Stored procedure help, makes server jump to 100%
      Hello, we have a users table with the following fields: client_id varchar 20 counter1 int counter2 int .. .. .. counter50 int
  3. #2

    Default Re: Re: Legacy ASP, SQL Server, Paging Stored Procedure - resend

    Forgot to say thanks, that worked!
    >-----Original Message-----
    >I'm not sure if this made it so I'm resending it (with
    correction):
    >
    >This is the best I could come up with. The only other
    >solutions I could think of involved cursors or dynamic
    >sql, both of which I try to avoid.
    >
    >create procedure getrecords (
    >@recsrequested tinyint) AS
    >set nocount on
    >
    >set rowcount @recsrequested
    >select personid into #temp from pimples order by personid
    >
    >set rowcount 0
    >select distinct personid into #temp2 from #temp
    >
    >select t1.personid,t1.fname,t1.lname,t2.location
    >from persons t1 inner join #temp2 t3
    >on t1.personid = t3.personid inner join pimples t2
    >on t1.personid = t2.personid
    >
    >drop table #temp
    >drop table #temp2
    >
    >
    >HTH,
    >Bob Barrows
    >
    >
    >aj wrote:
    >> Bob,
    >> sorry, my mistake it's 5. what I meant was...
    >> (1x3)+(1X2)
    >>
    >> Anyways,
    >>
    >> That is the result set....
    >>
    >> PersonID FName LName Location
    >> 2 Bart P Nose
    >> 2 Bart P Chin
    >> 2 Bart P Butt
    >> 3 Bob B Leg
    >> 3 Bob B Arm
    >>
    >> I want two records...
    >> dbconn.execute("getRecords 2")
    >>
    >> The getRecords proc will return the two records but I
    >> really want it to return 3 records because the third
    >> record is still PersonID and I want the proc to grab
    that
    >> record then stop.
    >>
    >> Here is what I want when I ask for 2 records...
    >> PersonID FName LName Location
    >> 2 Bart P Nose
    >> 2 Bart P Chin
    >> 2 Bart P Butt
    >>
    >> sorry for the confusion,
    >> aj
    >>
    >>> -----Original Message-----
    >>>
    >>>> -----Original Message-----
    >>>> sure....
    >>>>
    >>>> -------person-------- -------pimple--------
    >>>> PersonID FName LName Location PersonID
    >>>> 2 Bart P Nose 2
    >>>> 3 Bob B Chin 2
    >>>> Butt 2
    >>>> Leg 3
    >>>> Arm 3
    >>>>
    >>>>
    >>>> the query...
    >>>> select * from person inner join pimple on
    >>>> person.personid=pimple.pimpleid order by personID
    >>>>
    >>>> Which will return 2X5=10 rows
    >>>
    >>> Why do you think this query will return 10 rows? it
    should
    >>> only return 5 rows which will look like this (once you
    get
    >>> rid of the * and list the columns you want it to
    return):
    >>>
    >>> select t1.PersonID,t1.FName,t1.LName,t2.Location
    >>> from person t1 inner join pimple t2 on
    >>> t1.personid=t2.pimpleid order by t1.personID
    >>>
    >>> PersonID FName LName Location
    >>> 2 Bart P Nose
    >>> 2 Bart P Chin
    >>> 2 Bart P Butt
    >>> 3 Bob B Leg
    >>> 3 Bob B Arm
    >>>
    >>>>
    >>>> What I want the stored proc to do is know when to
    return
    >>>> records based on the number of records I pass it, plus
    >>>> more records if the "cursor" is still on an existing
    >>>> personID. Once it goes to a new PersonID, stop.
    >>>>
    >>> Again, how is what you want different from what this
    join
    >>> query returns already (see above)? Show me what you
    want
    >>> (in tabular form) instead of describing it.
    >>>
    >>> Bob Barrows
    >>> .
    >
    >
    >
    >.
    >
    AJ Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139