Create DatabaseFruitCreate TableFruit (Idsvarchar( -), Namevarchar( -), pricedecimal( -,2), Sourcevarchar( -), Stackint, Numbersint,Image varchar( -))Insert intoFruitValues('k001','Apple',2.4,'Yantai',2, the,'IMAGE/0.GF')Insert intoFruitValues('k002','Pineapple',1.4,'Guangdong',3, About,'IMAGE/1.GF')Insert intoFruitValues('k004','Grape',2.4,'Xinjiang',2,98,'IMAGE/3.GF')Insert intoFruitValues('k006','Peach',1.4,'Poon Tao',6,3,'IMAGE/5.GF')Insert intoFruitValues('k007','Banana',2.4,'Jinan',5, -,'IMAGE/6.GF')Select* fromFruit--Invoicing Stored ProceduresAlter procJinchuku@Ids varchar( -),@Name varchar( -),@Price decimal( -,2),@Source varchar( -),@Stack int,@Numbers int,@Image varchar( -) as if @Numbers>0 --Representative Stock begin Declare @shiok int --Define a variable Select @shiok=Numbers fromFruitwhereIds=@Ids --Use this variable to receive the corresponding number of input @ids if @shiok>0 --If there is such a goods, directly modify the inventory begin UpdateFruitSetNumbers=@Numbers+NumberswhereIds=@Ids --The number of changes to the input @ids corresponds to the line return 2--Arrival Success End Else --No such goods, add this kind of goods begin Insert intoFruitValues(@Ids,@Name,@Price,@Source,@Stack,@Numbers,@image) return 1--' Add variety success ' End End Else--representative Shipments begin Declare @isok int Select @isok=Numbers fromFruitwhereIds=@Ids if @isok>0 --There is this kind of goods, on the ship begin if @isok>ABS(@Numbers)--The inventory is larger than the shipping begin UpdateFruitSetNumbers=@Numbers+NumberswhereIds=@Ids return 0--' shipping Success ' End Else --less than the inventory to be shipped begin return -1--' in stock, but not enough ' End End Else --no such goods . begin return -2--' No such goods directly ' End EndGoDeclare @a intexec @a=Jinchuku'k001','Apple',2.4,'Yantai',2,-Ten,'IMAGE/0.GF'Print @aSelect * fromFruit
Invoicing stored Procedures