I'm having a hard time getting results from a stored procedure (from SQL Server 2000) and using them in a javascript ASP page (in IIS 5) by opening them somehow using ADO. The stored procedure is quite long, but it basically does something like:
CREATE PROCEDURE GetWeekBuckets(@CustomerID int, @EndDate datetime, @NumberOfWeeks int)
AS
CREATE TABLE #WeekBuckets (
ReportYear int NULL,
ReportWeek int NULL,
ReportBucket int NULL,
ReportAmount float NULL,
ReportCount float NULL
)
WHILE @NumberOfWeeks >= 0
BEGIN
INSERT INTO #WeekBuckets (ReportYear, ReportWeek, ReportBucket, ReportAmount, ReportCount)
SELECT DatePart(YEAR, @EndDate) AS ReportYear, DatePart(WEEK, @EndDate) AS ReportWeek,
dbo.GetBucket(DateDiff(DAY, InvoiceDate, @EndDate)) AS ReportBucket,
SUM(AmountImported) AS ReportAmount, COUNT(*) AS ReportCount
FROM MyData
WHERE (CloseDate IS NULL OR CloseDate > @EndDate) AND
InvoiceDate <= @EndDate
GROUP BY dbo.GetBucket(DateDiff(DAY, InvoiceDate, @EndDate))
SELECT @EndDate = DateAdd(WEEK, -1, @EndDate)
SELECT @NumberOfWeeks = @NumberOfWeeks - 1
END
SELECT * FROM #WeekBuckets ORDER BY ReportYear ASC, ReportWeek ASC
DROP TABLE #WeekBuckets
GO
It returns a beautiful recordset when asked to do so from the Query Analyzer:
EXEC GetWeekBuckets 1, '2006-01-01', 52
Now, I've gone through all sorts of possibilities in javascript ASP, by simply opening a recordset with the same text as what I executed in Query Analyzer, by using a Command object and them trying to assign it as a source to a recordset in a few different ways, but all to no avail. The error I'm getting is ADODB.Recordset (0x800A0E78), which says the operation is not allowed when the object is closed (when trying to loop through the recordset).
Any ideas?