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
 SQL Server Development (2000)
 checking for error

Author  Topic 

PeterG
Posting Yak Master

156 Posts

Posted - 2003-11-03 : 18:43:28
Q: When writing a stored proc where I do a select before doing a whole bunch of updates and inserts ( to different tables), do I check for error after doing the select? I know I'd have to do error checking after each update and insert.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-11-03 : 19:08:42
The error checking should come after updates, inserts, and deletes. It is not necessary to check for errors on selects.

SELECT @var1 = Column1
FROM Table1
WHERE Column2 = 0

UPDATE Table2
SET Column1 = @var1
WHERE Column2 = 0

IF @@ERROR = 0
COMMIT TRAN
ELSE
ROLLBACK TRAN

Tara
Go to Top of Page
   

- Advertisement -