Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Transaction syntax
Message
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
00686750
Message ID:
00686788
Views:
48
>Im just wondering if there is an eaiser way to accomplish this?

not really. SQL Server's error handling is very primitive.
I'm hopeing that things will change with Yukon.

The only suggestion that I have is to not do the second insert if the first fails. I see no reason to cause SQL Server to do work that will just be reversed. you could try something like this:

DECLARE @result int
INSERT INTO students ...
SET @result = @@ERROR

IF @result != 0 GOTO __cleanup

IF @logmove = 1
BEGIN
INSERT INTO movelog ...
SET @result = @@ERROR
END

__cleanup:
IF @result != 0
BEGIN
ROLLBACK TRANSACTION
RAISERROR('Unable to move student out.', 16, 1)
END
ELSE COMMIT TRANSACTION

RETURN @result
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform