Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Transaction syntax
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
00686750
Message ID:
00686788
Vues:
47
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform