基本信息
源码名称:简单的订单存储过程
源码大小:0.83KB
文件格式:.txt
开发语言:SQL
更新时间:2015-06-17
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

简单的订单存储过程


create Proc orderConfirm
@number nvarchar(50),
@userId int,
@address nvarchar(200),
@totalMoney money output
as
declare @error int
set @error = 0

select @totalMoney = SUM([Count]*UnitPrice) from Cart inner join Books on Cart.BookId=Books.BookId where Cart.UserId=@userId

begin transaction 

insert into Orders(OrderId,OrderDate,UserId,TotalPrice,Address,State) values (@number,GETDATE(),@userId,@totalMoney,@address,0)
set @error = @error @@ERROR

insert into OrderBook(OrderId,BookId,Quantity,UnitPrice) select @number,Cart.BookId,[Count],UnitPrice from Cart inner join Books on Cart.BookId=Books.BookId where Cart.UserId=@userId
set @error = @error @@ERROR

delete from Cart where UserId = @userId
set @error = @error @@ERROR

if @error>0
begin
 rollback transaction
end
else
begin
commit transaction
end