Solved

Pass Return Code to ASP Page

Posted on 2003-10-23
5
256 Views
Last Modified: 2012-06-21
below is my stored procedure. what i want to do is to return the value 1 or 0 to an asp page. How can i pass the value 1 or 0 to an ASP page?

CREATE PROCEDURE DoesRecordExist
   @pid int
AS

IF EXISTS(SELECT * FROM BasketItems WHERE ProductID = @pid)
   RETURN (1)
ELSE
   RETURN (0)
GO

thanks
0
Comment
Question by:jamaje
5 Comments
 
LVL 3

Accepted Solution

by:
SQLMaster earned 50 total points
ID: 9606439
Hi,

Instead of using a stored procedure, the best way will be to use a User Defined Function and catch the return value in the  recordset that will be passed to ASP page

Thanks
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 50 total points
ID: 9606931
Something like this (untested):
Dim cmd
Set cmd = Server.CreateObject("ADODB.Command")
With cmd
   .ActiveConnection = "your connection string goes here"
   .CommandText = "DoesRecordExist"
   .CommandType = adCmdStoredProc
   .Parameters.Append .CreateParameter("@RETURN_VALUE", adInteger, adParamReturnValue, 0)
   .Parameters.Append .CreateParameter("@pid", adInteger, adParamInput, 0,YourInputValueGoesHere)
   .Execute , , adExecuteNoRecords
   Response.Write .Parameters("@RETURN_VALUE").Value
End With
Set cmd = Nothing

Make sure you are including all the ADO constants (use adovbs.inc) or replace them with their corresponding values.

Anthony
0
 

Expert Comment

by:fromapu
ID: 9618947
hi
Let me modify the stored procedure a bit.

CREATE PROCEDURE DoesRecordExist
   @pid int,
   @Return Smallint Output
AS

IF EXISTS(SELECT * FROM BasketItems WHERE ProductID = @pid)
  Select @RETURN = 1
ELSE
   Select @RETURN = 0
GO

Then the ASP code:

dim cmd, prmPid, prmReturn, pid
pid = request("pid")
Set cmd = Server.createobject("ADODB.Command")
With cmd
         Set .activeconnection = "Your Connection object's name"
         .commandType = "adcmdStoredProc"
         .CommandText = "DoesRecordExist"
         
         Set prmPID = .CreateParameter("@PID",adInteger, adParamInput,4,pid
          .Parameters.Append prmPID

         Set prmReturn= .CreateParameter("@Return",adSmallint, adParamOutput,2)
          .Parameters.Append prmReturn

          .Execute

          Response.write .Parameters("@Return").Value
End With

I think this would work
Bye
fromapu
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now