新增的儲存過程

2021-05-10 05:17:48 字數 1388 閱讀 6325

begin transaction --開始事務

if exists(select 1 from [bmds_customerkindplan] where [year] = @year and [month] = @month and [customercode] = @customercode)

begin

raiserror('新增失敗,該記錄已存在',16,1)

commit transaction

return

endinsert into [bmds_customerkindplan](

[plancode],[year],[month],[customercode],[createdby]

)values(

@plancode,@year,@month,@customercode,@createdby

)if @@error!=0

begin

rollback transaction

select '0' as ifcando

endelse

begin

commit transaction

select @@identity as ifcando

end儲存過程

如果存在就修改,不存在就新增

if exists (select 1 from [bts_erp_distributionoffice] where [officecode]=@officecode)

update [bts_erp_distributionoffice] set

[officename] = @officename,[officenameb] = @officenameb,[companytype] = @companytype,[oilcategorytosell] = @oilcategorytosell,[oraganisecode] = @oraganisecode,[manager] = @manager,[orderindex] = @orderindex,[modifieddate] = getdate ()

where officecode=@officecode

else

insert into [bts_erp_distributionoffice](

[officecode],[officename],[officenameb],[companytype],[oilcategorytosell],[oraganisecode],[manager],[orderindex]

)values(

@officecode,@officename,@officenameb,@companytype,@oilcategorytosell,@oraganisecode,@manager,@orderindex

)

MySQL新增儲存過程

1.mysql的儲存過程與sqlserver是不同的。而且mysql相對比較輕量化,在寫的過程中,對函式與儲存過程的區分不是特別明顯。標準語法結構 delimiter 或 delimiter 這個地方沒別的意思,就是重新定義結束標識。將 變成了 begin delete from matches w...

SQL儲存過程新增新記錄

sql儲存過程新增新記錄 sql資料庫儲存過程語句 create proc sp adduser 儲存過程引數 username nvarchar 20 password nvarchar 20 realname nvarchar 30 nvarchar 10 useremail nvarchar ...

SQL儲存過程新增新記錄

sql儲存過程新增新記錄 sql資料庫儲存過程語句 create proc sp adduser 儲存過程引數 username nvarchar 20 password nvarchar 20 realname nvarchar 30 nvarchar 10 useremail nvarchar ...