Several SQL Server stored procedures were used to make the shopping cart system _mssql

Source: Internet
Author: User
That is, as a visitor to the site to log in as a cookie to store the shopping cart, and the identity of the logged-in user to enter the shopping cart information stored in the database, if the first to complete the shopping as tourists and then login to continue shopping, the cookies into the database;
The main stored procedures involved are as follows:
One: Members have been registered to add goods to the shopping cart function:
Copy Code code as follows:

/* @store_sum indicate the number of items to add, add and confirm whether the number of the cart is in excess of the quantity that will be added.
CREATE proc Ncp_cart_add
(
@store_id int,
@store_sum Int=1,
@member_id int
)
As

DECLARE @Amount int
DECLARE @NowAmount int
Begin
Select @Amount = (select Amount from Ncp_store where id= @store_id)
IF EXISTS (SELECT 1 from [Ncp_cart] WHERE store_id= @store_id and member_id= @member_id)
Begin
Select @NowAmount = (select store_sum+ @store_sum from Ncp_cart WHERE store_id= @store_id and member_id= @member_id)
If @NowAmount > @Amount
return 0
Else
UPDATE [Ncp_cart] SET store_sum=store_sum+ @store_sum, Addtime=getdate () where store_id= @store_id and member_id= @member _id
Return 1
End
ELSE
Begin
Select @NowAmount = (select Store_sum from Ncp_cart WHERE store_id= @store_id and member_id= @member_id)
If @NowAmount > @Amount
return 0
Else
INSERT into [Ncp_cart] (store_id,store_sum,member_id) VALUES (@store_id, @store_sum, @member_id)
Return 1
End
End
Go

Two: The Shopping cart deletion function

Copy Code code as follows:

/* Type 1 is all deleted 0 o'clock just delete A/*
CREATE PROCEDURE Ncp_cart_del
@type int=0,
@store_id int,
@member_id int
As
Begin
If @type =0
Delete FROM [Ncp_cart] where store_id= @store_id and member_id= @member_id
Else
Delete FROM [Ncp_cart] where member_id= @member_id
End
Go
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.