[quoted text, click to view] Beau wrote:
> Hi all, thanks in advance.
>
> Ok, heres the story.
> What is happening......
> --------------------------------
>
> I've got an ASP page that loops.
> It loops in order to get data in different, sequential date ranges.
> I.E. from 9/1/2000 - 10/1/2000 then 10/1/2000 - 11/1/2000 etc etc etc.
> It calls SPs using the 2 dates and an integer used for companyid
> reference.
>
> Let's just do this for 2 SP's (there are like 6 on the page.)
> One SP has 3 params, one has only 2.
>
> Now, the first iteration of the loop, it works. (because I'm
> response.writiting out the dates it's using to verify they are ok.
> The second time through I get the following error when I try to
> execute the following ASP:
>
> Set rstStoredProc = cmdStoredProc.Execute(, Array(GroupChoice,
> fromdate, todate))
> ______________________________________________
> ADODB.Command error '800a0bb9'
>
> Arguments are of the wrong type, are out of acceptable range, or are
> in conflict with one another.
>
> _______________________________________________
>
>
>
> What I need to do.........
>
> --------------------
>
> In the loop, I am trying to reuse my command/connection objects
> instead of reinstantiating them for each iteration of the loop.
You don't need to even use a Command object. You can execute the below
procedures simply by doing this (assuming you've got a connection object
with the sensible name of cn):
set rstStoredProc2 =createobject("adodb.recordset")
cn.proc_getPageHits GroupChoice,fromdate,todate,rstStoredProc2
set rstStoredProc =createobject("adodb.recordset")
cn.proc_getUserCount GroupChoice,todate,rstStoredProc
[quoted text, click to view] > ***Currently, it must use ODBC not OLEDB so keep that in mind.***
This is irrelevant, but ... Why is that? I've never seen a good reason for
using the obsolete ODBC driver.
[quoted text, click to view] >
>
>
> Here's the code for the SP's
> --------------------
>
> CREATE Procedure proc_getPageHits
> (
> @GroupID int,
> @FromDate datetime,
> @ToDate datetime
> )
> As
--you forgot to include this:
SET NOCOUNT ON
[quoted text, click to view] > SELECT sum(counter) as hitcount
> FROM tblTracking
> WHERE CreateUserID in (select UserID from tblUser where GroupID=
> @GroupID)
> and (CreateDate between @FromDate and @ToDate)
SELECT sum(counter) as hitcount
FROM tblTracking t INNER JOIN tblUser u
ON t.CreateUserID = u.UserID AND u.GroupID = @GroupID
WHERE t.CreateDate between @FromDate and @ToDate
[quoted text, click to view] > GO
>
>
>
> CREATE Procedure proc_getUserCount
> (
> @GroupID int,
> @ToDate datetime
> )
> As
--Again:
SET NOCOUNT ON
[quoted text, click to view] > SELECT count(UserID) as usercount
> FROM tblUser
> WHERE (GroupID = @GroupID) and (CreateDate < @ToDate)
> GO
>
Actually, this can be done with a single stored procedure:
CREATE Procedure proc_getUserCountAndPageHits (
@GroupID int,
@FromDate datetime,
@ToDate datetime,
@Users int output
)
As
SET NOCOUNT ON
SELECT @users=count(UserID) as usercount
FROM tblUser
WHERE (GroupID = @GroupID) and (CreateDate < @ToDate)
SELECT sum(counter) as hitcount
FROM tblTracking t INNER JOIN tblUser u
ON t.CreateUserID = u.UserID AND u.GroupID = @GroupID
WHERE t.CreateDate between @FromDate and @ToDate
go
Of course, you are back to needing to use a Command object in order to
retrieve the output parameter value. Also, you will no longer be able to use
the Array method to execute the procedure. You will need to use
CreateParameter statements to create the Parameters collection. I've posted
code for doing this before.
Slightly less efficiently, you can do this to avoid writing the
CreateParameter statements:
CREATE Procedure proc_getUserCountAndPageHits (
@GroupID int,
@FromDate datetime,
@ToDate datetime
)
As
SET NOCOUNT ON
EXEC proc_getUserCount @GroupID, @ToDate
SELECT sum(counter) as hitcount
FROM tblTracking t INNER JOIN tblUser u
ON t.CreateUserID = u.UserID AND u.GroupID = @GroupID
WHERE t.CreateDate between @FromDate and @ToDate
go
And in ASP:
set rstStoredProc =createobject("adodb.recordset")
cn.proc_getUserCountAndPageHits GroupChoice,fromdate, _
todate,rstStoredProc2
set rstStoredProc2 = rstStoredProc.NextRecordset
Bob Barrows
PS. .inetserver.asp.db was the only group for which this question was
relevant. There was no need to crosspost to so many groups, especially the
irrelevant ones. I've set the Followup-To to
microsoft.public.inetserver.asp.db
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.