Use [Quanli]
GO
/****** object:storedprocedure [dbo]. [Buycar] Script date:11/12/2016 08:25:25 ******/
SET ANSI_NULLS on
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo]. [Buycar]--Creating a stored procedure Bycar
(
@Purchase_State varchar (200),--Document status
@Purchase_Remark varchar (200),--remarks
@Supplier_Id int,--foreign key supplier code
@WareHose_Id int,--FOREIGN key warehouse code
@Employee_Id int,--operator
@xml XML--xml Data flow
)
As
Begin Tran T12--Transaction name
Insert into Purchase (purchase_curom,purchase_date,purchase_state,purchase_remark,supplier_id,warehose_id, EMPLOYEE_ID)
VALUES (CONVERT (int,getdate), GETDATE (), @Purchase_State, @Purchase_Remark, @Supplier_Id, @WareHose_Id, @ EMPLOYEE_ID)
declare @id int, @pointer INT--Define parameters
Set @[email protected] @IDENTITY;---get the self-increment field
CREATE TABLE #oo---creating a temp table
(
purchase_id int,--Purchase Main Table number (foreign key)
product_id int,--Product number (foreign key)
Purchasemate_num int,--Purchase quantity
Purchasemate_price Decimal,--Commodity price
Purchasemate_sum decimal--Total merchandise price
)
Execute sp_xml_preparedocument @pointer OUTPUT, @xml--sp_xml_preparedocument statement--Adds a data loop of XML type to the staging table
Insert into #oo (product_id,purchasemate_num,purchasemate_price,purchasemate_sum)
Select Product_id,purchasemate_num,purchasemate_price,purchasemate_sum from OpenXML (@pointer, '/xml/product ')-- System program sp_xml_preparedocument point to '/xml/product '
With (
product_id int,--Product code
Purchasemate_num int,--Purchase quantity
Purchasemate_price Decimal,--Commodity price
Purchasemate_sum decimal--Total merchandise price
)
Update #oo set [email protected]--Modify values
Insert into Purchasemate (purchase_id,product_id,purchasemate_num,purchasemate_price,purchasemate_sum) Select Purchase_id,product_id,purchasemate_num,purchasemate_price,purchasemate_sum from #oo
if (@ @ERROR <>0)
Begin
Rollback TRAN T12--rollback
return 0
End
Else
Begin
Commit Tran T12--Submit
Return 1
End
Shopping cart Business