"Lee" <lee_nospam_@artjunky.com> wrote in message
news:er20df$p5h$1@forums.macromedia.com...
> Lee wrote:
>> By redundant do you mean the begin and end?
>
> It just occurred to me that you didn't see the insert
and update. What I
> am thinking here, I want one to INSERT and one to
UPDATE. the insert will
> be a brand new record while the update would update a
current record.
>
> I just realized that what I did would not work because
it needs an ID to
> update a record I only want it to update a record that
is already in the
> data.
>
> The INSERT, however, doesn't matter because it's a new
record.
You could have a procedure that does both. There's no special
benefit to
having one that does both over having two separate ones. If
you wanted,
though:
CREATE PROCEDURE [dbo].[HandleUpdate]
@RecID INT=NULL OUTPUT,
@ValA VARCHAR(20)
AS
BEGIN
SET NOCOUNT ON;
IF @RecID IS NULL
BEGIN
INSERT INTO dbo.TableA(ColA)
VALUES(@ValA)
SET @RecID=SCOPE_IDENTITY()
END
ELSE
BEGIN
UPDATE dbo.TableA
SET ColA = @ValA
WHERE RecID = @RecID
END
END
In DW, to do an insert, either leave out the RecID
parameter's value
entirely, or set the variable to the keyword Empty or Null
first.
myCommand.Parameters.Append
myCommand.CreateParameter("@RecID",3,3,4,RecID)
The first 3 indicates you're passing an integer; the second 3
indicates it's
an input/output parameter (1 for input, 2 for output, 3 for
both); and 4 is
the size of an integer in bytes. If RecID is an integer, the
procedure will
update. If you set RecID = Empty, then the procedure will
insert. After an
insert, you can get the ID of the new record after the
.Execute() line.
newID = myCommand.Parameters("@RecID").Value
It sometimes comes in handy for a redirect to a detail page
or something.