Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
First SP
Message
De
28/02/2003 17:49:24
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Titre:
Divers
Thread ID:
00759576
Message ID:
00759752
Vues:
35
This message has been marked as a message which has helped to the initial question of the thread.
This is what I would do:
-- validate inputs and stuff like that here ---
DECLARE @CartID  int, @Err int, @RowCountVar int

SET @Err = 0
SET @RowCountVar = 0

IF EXISTS (SELECT CartID FROM cart WHERE UserID = @tcUserID)
   BEGIN
   	UPDATE cart
   	SET @CartID = CartID,
   	LastModTs = CURRENT_TIMESTAMP
   	WHERE UserID = @tcUserID

   END
ELSE
-- New User
    BEGIN
	 INSERT INTO cart (UserID) values (@tcUserID)
         SELECT @InsErr = @@ERROR, @RowCountVar = @@ROWCOUNT,
	        @CartID = SCOPE_IDENTITY()
     END

SELECT @Err = @@ERROR, @RowCountVar = @@ROWCOUNT

IF @err != 0 
begin
 raiserror('unable to create or update cart', 16, 1)
 goto __cleanup
end

-- Now continue with CartContent table
   INSERT INTO CartContent
            (CartID, NumOfRecords,
            CreditCategory, DescriptionText, SelectionCriteria)
            values (@CartID, @tnNumOfRecords, @tcCreditCategory,
                    @tcDescription, @tcSelectionCriteria)

     SELECT @Err = @@ERROR, @RowCountVar = @@ROWCOUNT

     IF @Err != 0
        BEGIN
 raiserror('unable to add item to the cart', 16, 1)
 goto __cleanup
        END

__cleanup:
if @err != 0
begin
 rollback transaction
 return 1
end
else
begin
 commit transaction
 return 0
end
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