Sql server存储过程以及一次插入多条记录 【百科全说】

您所在的位置:网站首页 冠军之箭艾希怎么得 Sql server存储过程以及一次插入多条记录 【百科全说】

Sql server存储过程以及一次插入多条记录 【百科全说】

2023-02-26 22:42| 来源: 网络整理| 查看: 265

首先简单介绍sql server存储过程吧。至于概念含义啥的就不做过多介绍了。它其实和mysql有些类似,语法大同小异。还是用例子说明问题吧。

CREATE PROCEDURE insert_supplier

@supplier_name varchar(30),

@supplier_contact varchar(30),

--------------------------------输入参数

@theoutputstring varchar(50) output

-------------------------------输出参数

AS

BEGIN TRAN

SET XACT_ABORT OFF

-------------------------------事务操作开始与 SET XACT_ABORT ON

-------------------------------和if (@theresult=0)

begin

--------------------------------------------------------------------------------------begin

if (@theresult=1)

begin

insert into supplier

(supplier_name,supplier_contact,supplier_phone,supplier_fax,supplier_email,

supplier_postcode,supplier_remark,supplier_address,

supplier_website,supplier_telephone)

values

(@supplier_name,@supplier_contact,@supplier_phone,@supplier_fax,@supplier_email,

@supplier_postcode,@supplier_remark,@supplier_address,

@supplier_website,@supplier_telephone)

if (@@rowcount1) set @theresult=-2

end

------------------------------------------------------------------------------------end

end

SET XACT_ABORT ON

if (@theresult=0)

begin

insert into sale_record(sale_id,client_name,employee_id,transaction_id,warehouse_id,sale_time,sale_num,sale_totalprice,sale_logistics,sale_logisticscode)

values(@sale_id,@client_name,@employee_id,@transaction_id,@warehouse_id,@sale_time,@sale_num,@sale_totalprice,@sale_logistics,@sale_logisticscode)

if (@@rowcount1) set @theresult=-2

end

if(@theresult>=0)

begin

set @prepoint = 1

set @curpoint = charindex('$',@tmp_localitem_id)

set @prepoint_price = 1

set @curpoint_price = charindex('$',@tmp_sale_price)

while @curpoint>0 and @theresult>=0

begin

set @localitem_id = substring(@tmp_localitem_id,@prepoint,@curpoint-@prepoint)

set @sale_price = substring(@tmp_sale_price,@prepoint_price,@curpoint_price-@prepoint_price)

insert into sale_detail(localitem_id,transaction_id,sale_id,sale_price)values(@localitem_id,@transaction_id,@sale_id,@sale_price)

if (@@rowcount1) set @theresult=-3

if(@theresult>=0)

begin

update storage set localitem_num = '0' where localitem_id = @localitem_id

if (@@rowcount1) set @theresult=-4

end

set @prepoint=@curpoint+1

set @prepoint_price=@curpoint_price+1

set @curpoint=charindex('$',@tmp_localitem_id,@prepoint)

set @curpoint_price=charindex('$',@tmp_sale_price,@prepoint_price)

end

end

SET XACT_ABORT ON

set @theresult=1

if (@theresult



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3