标签:varchar dealloc arc service -- 创建 serve pen after
游标主要是用于循环遍历
alter TRIGGER [dbo].[z_area_service_provider]
ON [dbo].[z_area]
AFTER UPDATE
AS
declare @id varchar(50)
declare @update_name varchar(255)
declare @service_provider_id varchar(255)
declare @col varchar(255)
select @id=id,@service_provider_id=service_provider_id,@update_name=update_by from inserted
if UPDATE(service_provider_id) and iSNULL(@service_provider_id,‘‘)!=‘‘
begin
select * into #t from [f_splitSTR]((select service_provider_id from z_area where id=@id ),‘,‘)
DECLARE #point_cursor CURSOR
FOR
select * from #t --每条信息从头到尾的写入 -- 创建临时表
OPEN #point_cursor
FETCH NEXT FROM #point_cursor INTO @col
while @@fetch_status = 0
begin
if not exists(select * from z_area_provider where area_id =@id and service_provider_id=@col)
begin
insert into z_area_provider(id,create_date,create_by,service_provider_id,area_id)
values(NEWID(),GETDATE(),@update_name,@col,@id)
end
FETCH NEXT FROM #point_cursor INTO @col
END
CLOSE #point_cursor
DEALLOCATE #point_cursor
drop table #t 删除临时表
end
标签:varchar dealloc arc service -- 创建 serve pen after
原文地址:https://www.cnblogs.com/myxz/p/12913192.html