“(select company_class1id from inserted)<>(select company_class1id from deleted)”
这句有问题,集合之间不能进行“<>”的运算,建议试一试游标。
declare cur1 cursor for select company_class1id from inserted
declare cur2 cursor for select company_class1id from deleted
declare @inserted 'Company_classid的类型'
declare @deleted 'Company_classid的类型'
open cur1
open cur2
fetch next from cur1 into @insert
while @@fetch_status==0
begin
fetch next from cur2 into @deleted
while @@fetch_status==0
begin
if (@inserted)<>(deleted)
begin
'计数'
break
end
else
begin
continue
end
end
end
这只是个大概的算法和建议。
这句有问题,集合之间不能进行“<>”的运算,建议试一试游标。
declare cur1 cursor for select company_class1id from inserted
declare cur2 cursor for select company_class1id from deleted
declare @inserted 'Company_classid的类型'
declare @deleted 'Company_classid的类型'
open cur1
open cur2
fetch next from cur1 into @insert
while @@fetch_status==0
begin
fetch next from cur2 into @deleted
while @@fetch_status==0
begin
if (@inserted)<>(deleted)
begin
'计数'
break
end
else
begin
continue
end
end
end
这只是个大概的算法和建议。
for insert
as
--原有企业分类计数器处理
declare @type varchar(60),@num int
select @type = company_bigclass from inserted
set @num=charindex(',',@type+',')
while @num>1
begin
update comclass set comclass_recordcount=comclass_recordcount+1 where comclass_name= ltrim(rtrim( left(@type,@num-1)))
select @type=substring(@type,@num+1,len(@type)),@num=charindex(',',@type+',')
end
--一级分类计数器处理
update company_class set class_recordcount=class_recordcount+1 where class_id=( select company_class1id from inserted)
--二级分类计数器处理
declare @type2 varchar(50),@num2 int
select @type2 = company_class2id from inserted
set @num2=charindex(',',@type2+',')
while @num2>1
begin
update company_class set class_recordcount=class_recordcount+1 where class_id=convert(int, ltrim(rtrim( left(@type2,@num2-1))))
select @type2=substring(@type2,@num2+1,len(@type2)),@num2=charindex(',',@type2+',')
end
--三级分类计数器处理
declare @type3 varchar(2000),@num3 int
select @type3 = company_class3id from inserted
set @num3=charindex(',',@type3+',')
while @num3>1
begin
update company_class set class_recordcount=class_recordcount+1 where class_id= convert(int,ltrim(rtrim( left(@type3,@num3-1))))
select @type3=substring(@type3,@num3+1,len(@type3)),@num3=charindex(',',@type3+',')
end刚才我试了一下批量插入,也出现一样的错误!!!!!
如果不只是一条,就该为
(select company_class1id from inserted) not in (select company_class1id from deleted)
不知道可不可以
改为
update company_class set class_recordcount=class_recordcount+1 where class_id in ( select company_class1id from inserted)
所以还是会出现同样的错误。