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)
 No Matches

Author  Topic 

ann
Posting Yak Master

220 Posts

Posted - 2006-07-08 : 09:09:35
How do you return a value from your sp when you don't find a match? I am doing insert with a where clause, but I want to know if there is no match on it? Can this be done simply?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-07-08 : 09:13:14
you can use @@rowcount inside your SP to check and return a value via the OUTPUT parameter.


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-07-10 : 02:55:13
or can you post the code you used? What do you mean by no matches in insert statement?

Madhivanan

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

ann
Posting Yak Master

220 Posts

Posted - 2006-07-10 : 08:58:38
I want to know when something doesn't get inserted - I have to let the user know so they can do something else with the data:
ALTER PROCEDURE UpdateSatisfied
@NoteID int
,@CreateDate datetime
,@NoteAuthor VARCHAR(20)
,@CaseNote CHAR(12)
,@fraudCaseID int

AS

BEGIN TRAN
UPDATE SatisfyNotes
SET
NoteAuthor = @NoteAuthor
,CreateDate = @CreateDate
,CaseNote = @CaseNote

WHERE CaseNotes.NoteID = @NoteID
IF (@@ERROR <> 0) GOTO ERR_HANDLER

INSERT INTO CaseNotes(NoteStatus)
VALUES ('Satisfied')
WHERE CaseNotes.NoteID = @NoteID

IF (@@ERROR <> 0) GOTO ERR_HANDLER

COMMIT TRAN

RETURN 0

ERR_HANDLER:

ROLLBACK TRAN
RETURN 1
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-07-10 : 09:01:35
Do you need UPSERT? (Update when matched records;Insert if new)


Madhivanan

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

- Advertisement -