Store Procedure IF Else Newbie Question
Can somebody please help me out here. I am trying to write some code that will determine whether to INSERT or UPDATE depending on if the @StoryID has a value or not. I have tried
@StoryID = NULL , IS NULL = "" just about everything I can think of. What is happening is that it always INSERTS, it will not update. Any help is greatly appreciated.
CREATE PROCEDURE sp_ModifyStories
(
@StoryID int,
@StoryDate datetime,
@StoryNo varchar(100),
@StoryTitle varchar(200),
@ModifiedID int OUTPUT
)
AS
IF @StoryID < 1
BEGIN
INSERT INTO Stories
(Story_Date, Story_No, Story_Title)
VALUES
(@StoryDate, @StoryNo, @StoryTitle)
SELECT @ModifiedID = @@IDENTITY
END
ELSE
BEGIN
UPDATE Stories
SET
Story_Date = @StoryDate,
Story_No = @StoryNo,
Story_Title = @StoryTitle,
WHERE Story_ID = @StoryID
END
GO
Thanks
MIke
__________________
Peace
Mike
http://www.eclecticpixel.com
|