Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
First SP
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Titre:
Divers
Thread ID:
00759576
Message ID:
00759686
Vues:
28
Sergey,

See my question inline

>See corrections inline.
>>
>>/*
>>   If exists, grab CartID and update LastModified field
>>   otherwise insert a record and grab generated CartID
>>*/
>>/* The code bellow belongs to Bob Archer
>>
>>-- Code from Mike Levy
>
>DECLARE @ErrCode
>SET @ErrCode = 0
>
>>IF EXISTS (SELECT CartID FROM cart WHERE UserID = @tcUserID)

?? Should be BEGIN
>>   UPDATE cart
>>   SET LastModTs = CURRENT_TIMESTAMP,
>>   @CartID = CartID
>>   FROM cart
>>   WHERE UserID = @tcUserID
>    SET @ErrCode = @@ERROR
 ?? Should be END (otherwise SET @ErrCode would be executed regardless of IF condition)

>>ELSE
>>        BEGIN
>>	   INSERT INTO cart (UserID) values (@tcUserID)
>           SET @ErrCode = @@ERROR
>>
>>	   SELECT @CartID = SCOPE_IDENTITY()
>>        END
>>
>>     IF @ErrorCode <> 0   -- CNG
>>        BEGIN
>>            ROLLBACK TRAN
>>            PRINT 'ERROR: An error occurred while attempting to insert record to the Cart Table.'
>>            RETURN 4
>>        END
>>
>>Basically, I want to check, if my insert was correct or my update was correct. In both cases, if something got wrong, I need to rollback and get out from procedure.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform