Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Message from discussion ASP / Stored Procedure SQL Insert Help
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Bob Barrows  
View profile  
 More options Oct 11 2003, 11:39 am
Newsgroups: microsoft.public.inetserver.asp.general
From: "Bob Barrows" <reb01...@NOyahoo.SPAMcom>
Date: Sat, 11 Oct 2003 11:35:36 -0400
Local: Sat, Oct 11 2003 11:35 am
Subject: Re: ASP / Stored Procedure SQL Insert Help

Bill Kellaway wrote:
> Thanks Bob,

> I'm not sure what the Return Parameter does.  I'll take a guess
> though - please correct me if I'm wrong - It's SQL's way of telling
> the Command object if the command was successful or not ???

Close. The Return parameter contains the value returned by a RETURN
statement in your SP. If you do not have a RETURN statement, a successful
procedure will return 0, while a procedure that raises an error will return
NULL.

There are 3 ways to return values from a SQL Server stored procedure:
1. a Select statement that returns a resultset
--run this script in Query Analyzer (QA):
Create Procedure SelectValue
(@input    int)
AS
Select @input + 5
go
exec SelectValue 10
go
drop procedure SelectValue

2. a Return parameter:
--run this script in QA:
create procedure ReturnValue
(@input    int)
AS
Return @input + 5
go
declare @returnvalue    int
exec @returnvalue = ReturnValue 10
select @returnvalue
go
drop procedure ReturnValue

3. an Output Parameter:
--run this script in QA:
create procedure OutputValue
(@input    int output)
AS
SET @input = @input + 5
go
declare @outputvalue int
SET @outputvalue = 10
exec  OutputValue @outputvalue output
select @outputvalue
go
drop procedure OutputValue

I do not recommend method 1 for returning a single value. A resultset is
expensive to build, in that it must contain metadata in addition to data. So
more network traffic is created, and the client app needs to expend more
resources in order to retrieve and expose the resultset to the calling
procedure.

Most developers use the Return parameter to return status codes instead of
data. This is for the sake of consistency: there is no technical reason not
to use RETURN to return data, except that RETURN can only be used to return
integers. If you need to return other datatypes, you need to use an output
parameter.

> If so,
> this would be very helpful to me.  The reason that I changed this
> page from ADO to a SP Insert was that I was getting intermittant
> duplicate inserts.   Rebooting SQL seemed to help for awhile.

Very strange. Did you have a unique index to prevent duplicate inserts?

> Might I be able to use a return parameter to prevent duplicate
> inserts from the ASP page ???

Yes, but you don't have to. You can use EXISTS in your stored procedure to
do this without raising an error:

IF NOT EXISTS
    (Select * from sometable
    where somecolumn=<data_to_be_inserted>)
BEGIN
    INSERT sometable ...
END
--optionally - do this only if you want your client app to know
ELSE
BEGIN
    RETURN 2
    --code which you create to designate that record exists
END

HTH,
Bob Barrows


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.