Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SOLVED: Part of SP not running..Any Ideas?

Author  Topic 

FruitBatInShades
Yak Posting Veteran

51 Posts

Posted - 2006-06-23 : 09:18:01
With the following procedure FAQAnswers is never created or updated but SQL Never throws an error! Any ideas?
CREATE PROCEDURE FAQ_Answer
(
@UniqueID bigint,
@ReplyUserID bigint,
@Answer text,
@Question varchar(1024) = null,
@Status smallint ,
@CategoryID int,
@Published tinyint,
@Title varchar(128)
)
AS
/* Update answer */
IF EXISTS(Select QuestionID FROM FAQAnswers Where QuestionID=@UniqueID)
/* Not existing yet so add it */
BEGIN
INSERT INTO FAQAnswers
(
QuestionID,
ReplyUserID,
AnsweredOn,
Answer,
LastEdited,
EditedBy
)
VALUES
(
@UniqueID,
@ReplyUserID,
getdate(),
@Answer,
getdate(),
@ReplyUserID
);
END
ELSE
BEGIN
/* Exists So update */
UPDATE FAQAnswers
SET
LastEdited=getdate(),
EditedBy = @ReplyUserID,
Answer=COALESCE(@Answer,Answer)
WHERE QuestionID = @UniqueID;
END
/* update question */

UPDATE FAQQuestions
SET
Question=COALESCE(@Question,Question),
Status=@Status,
CategoryID=@CategoryID,
Published=@Published,
Title=COALESCE(@Title,Title)
WHERE UniqueID=@UniqueID

GO

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-23 : 09:27:39
I think EXISTS should be NOT EXISTS

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

FruitBatInShades
Yak Posting Veteran

51 Posts

Posted - 2006-06-23 : 09:30:07
*Fetches big stick, attaches to a windmill and waits for sense to beaten in* *THUNK* *THUNK* *THUNK*

Thanks madhivanan
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-23 : 09:47:36
So you need UPSERT

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -