SQLServer存储过程 实例,很多语法可以以后参考

时间:2022-03-29 14:06:00
SQL代码

alter
PROCEDURE sp_addnewdtgtype ( @dtgtypename varchar(50), @dtgdllcontent image, @returnmessage varchar(100) ) AS BEGIN declare @dtgtableaddsql varchar(300); declare @v_count int; declare @yyyymmddhhmm char(12); select @v_count=COUNT(1) from tb_DTGs where dtgname=@dtgtypename; if(@v_count=0) begin set @returnmessage='注册失败,该类型名称已存在' return 0 end else begin begin begin try begin tran select @yyyymmddhhmm=datename(year,GETDATE())+right('0'+DATENAME(MONTH,GETDATE()),2)+right('0'+DATENAME(DAY,GETDATE()),2)+right('0'+DATENAME(HOUR,GETDATE()),2)+right('0'+DATENAME(MINUTE,GETDATE()),2) insert into tb_DTGs(dtgid,dtgname,dtgdllcontent,createtime,updatetime) values(@v_count,@dtgtypename,@dtgdllcontent,@yyyymmddhhmm,@yyyymmddhhmm) commit tran end try begin catch rollback tran set @returnmessage='数据库未知错误,操作未能成功'; return 0 end catch end end END GO