12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- if (object_id('tgr_dindansp_insert','tr') is not null)
- drop trigger tgr_dindansp_insert
- go
- create trigger tgr_dindansp_insert on dindansp for insert
- as
- begin transaction
- declare @order nvarchar(24)
- declare @spid nvarchar(64)
-
- select @order = id, @spid = spid from inserted
- if (@spid is not null and @spid <> '')
- update dindan set [status3] = '未取' where [id] = @order
- commit transaction
- go
- if (object_id('tgr_dindansp_update','tr') is not null)
- drop trigger tgr_dindansp_update
- go
- create trigger tgr_dindansp_update on dindansp for update
- as
- begin transaction
- declare @order nvarchar(24)
- declare @countAll int
- declare @countOK int
-
- select @order = id from inserted
- select @countAll=count(*) from dindansp where [id] = @order
- select @countOK=count(*) from dindansp where [id] = @order and [status2] = 'OK' and ( spid is not null and spid <> '')
- if ( @countAll = @countOK )
- update dindan set [status3] = 'OK' where [id] = @order
- else
- update dindan set [status3] = '未取' where [id] = @order
- commit transaction
- go
- if (object_id('tgr_dindansp_delete','tr') is not null)
- drop trigger tgr_dindansp_delete
- go
- create trigger tgr_dindansp_delete on dindansp for delete
- as
- begin transaction
- declare @order nvarchar(24)
- declare @countAll int
- declare @countOK int
-
- select @order = id from deleted
- select @countAll=count(*) from dindansp where [id] = @order
- select @countOK=count(*) from dindansp where [id] = @order and [status2] = 'OK' and ( spid is not null and spid <> '')
- if ( @countAll = @countOK )
- update dindan set [status3] = 'OK' where [id] = @order
- commit transaction
- go
- select identity(int,1,1) as aid, autoid, zs into
- declare @maxid int
- declare @id nvarchar(50)
- declare @zs nvarchar(20)
- select @maxid = max(aid) from
- while @maxid > 0
- begin
- select @id = autoid, @zs = zs from
- update dindansp set zs = @zs where autoid = @id
- set @maxid = @maxid -1
- end
- drop table
|