Solved

Pass Return Code to ASP Page

Posted on 2003-10-23
5
257 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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL for Frequently Bought With 11 45
TSQL Where clause for Date with CASE - what is wrong? 11 71
SQL FUll Text Not returning any results 2 15
TSQL - IF ELSE? 3 24
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

948 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

18 Experts available now in Live!

Get 1:1 Help Now