栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 数据库 > MySQL > MsSql

做购物车系统时利用到得几个sqlserver 存储过程

MsSql 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

做购物车系统时利用到得几个sqlserver 存储过程

即以游客身份登录网站时以cookie的方式存储购物车,而以登录用户的身份进入时将购物车信息存储到数据库中去,若是先以游客身份完成购物再登录继续购物,则将cookies购物车存入数据库;
其中涉及到的存储过程主要如下:
一:已登录会员添加商品到购物车功能:
复制代码 代码如下:

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

二:购物车的删除功能

复制代码 代码如下:

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
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/170524.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号