In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
SQLServer stored procedures how to use transactions, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
The specific code is as follows
Create proc usp_Stock@GoodsId int,@ Number int,@ StockPrice money, @ SupplierId int,@ EmpId int,@ StockUnit varchar (50), @ StockDate datetime, @ TotalMoney money, @ ActMoney money, @ baseId int,@Description nvarchar (255) as declare @ error int = 0-- error record of operation in transaction-- Open transaction begin transaction-- add insert into StockInfo values (@ GoodsId, @ Number, @ StockPrice, @ SupplierId, @ EmpId) to purchase information. @ StockUnit, @ StockDate, @ TotalMoney, @ ActMoney,DEFAULT,@Description, @ baseId) set @ error+=@@ERROR-- record the possible error number-- the identification column for obtaining the current purchase information-- determine whether the current item has a purchase record if exists (select * from dbo.InventoryInfo where goodid=@GoodsId)-- indicate that the record exists. Directly modify the inventory quantity begin update dbo.InventoryInfo set GNumber=GNumber+@Number,TotalMoney+=@TotalMoney where goodid=@GoodsId set @ error+=@@ERROR-- record the possible error number end else-- this item has never been purchased. Then you should add the new existence information begin declare @ GWarningNum int-- the early warning quantity of this item-- to get the early warning quantity set @ GWarningNum= (select WaringNum from dbo.GoodsInfo where GId=@GoodsId) insert into dbo.InventoryInfo values (@ GoodsId,@Number,@baseId,@GWarningNum,@TotalMoney,' first purchase). Default) set @ error+=@@ERROR-record the possible error number end-- to determine the commit of the transaction or roll back if (@ error0) begin rollback transaction return-1-set the error identification of the operation result endelse begin commit transaction return 1-is it helpful for you to read the above after reading the endgo that the operation is successful? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.