Search code examples
sqlsql-serverasp-classicsql-server-2000

Can't return recordcount with the stored procedure with the declaration in it


I wrote a stored procedure to return the record but as soon as I declare a variable my asp classic can't do count the total recordset, it always returns -1

If anyone has the solution to this problem it would make my job a lot easier and your input would be greatly appreciated.

Stored proceedure code for SQL Server 2000

CREATE PROCEDURE sp_SalesTaxV3(
    @ship_zip varchar(20)
)
AS
   --problem  if in enable the next 2 lines
   DECLARE @tax_rate INT
   set @tax_rate =0
   --disable the above 2 line the asp will able to count.   
   --end problem
BEGIN
    SELECT * FROM tax_rate where  zip =''+@ship_zip+''  
END

ASP Classic code:

<%
set strGetTaxZips = Server.CreateObject("ADODB.RecordSet")
strSQLGetTaxZips = "EXECUTE sp_SalesTaxV3 '"&user_zip &"'"
Response.Write(strSQLGetTaxZips)
strGetTaxZips.Open strSQLGetTaxZips,tax_db,3
Response.Write("<BR>recordcount" &strGetTaxZips.recordcount)
%>

Solution

  • I would try to put the DECLARE after the BEGIN:

    CREATE PROCEDURE sp_SalesTaxV3(@ship_zip varchar(20))
    AS BEGIN
       DECLARE @tax_rate INT
       SET @tax_rate = 0
    
       SELECT * FROM tax_rate WHERE zip = ''+@ship_zip+''  
    END