发布网友 发布时间:2022-04-11 15:21
共1个回答
热心网友 时间:2022-04-11 16:50
你知道增加 baozhuangID ,说明还是自己考虑过了。执行以下的语句就可以了 ALTER TRIGGER [dbo].[testTri] ON [dbo].[BZDM] after INSERT,UPDATE AS BEGIN SET NOCOUNT ON; --insert操作的 update BZDM set baozhuangdaima = CAST(a.banbenhao as varchar) +'-' +CAST(a.long as varchar) +'-' +CAST(a.wit as varchar) +'-' +CAST(a.high as varchar) +'-' +CAST(a.beizhu as varchar) from BZDM a, inserted b where a.baozhuangID = b.baozhuangID and isnull(a.baozhuangdaima,'') = ''--只修改没有baozhuangdaima的记录,不要可注释掉 and isnull(a.baozhuangmingcheng,'') in ('ZX','ZH') update BZDM set baozhuangdaima = b.baozhuangmingcheng from BZDM a, inserted b where a.baozhuangID = b.baozhuangID and isnull(a.baozhuangdaima,'') = ''--只修改没有baozhuangdaima的记录,不要可注释掉 and isnull(a.baozhuangmingcheng,'') not in ('ZX','ZH') --update操作的 update BZDM set baozhuangdaima = CAST(a.banbenhao as varchar) +'-' +CAST(a.long as varchar) +'-' +CAST(a.wit as varchar) +'-' +CAST(a.high as varchar) +'-' +CAST(a.beizhu as varchar) from BZDM a, deleted b where a.baozhuangID = b.baozhuangID --and isnull(a.baozhuangdaima,'') = ''--只修改没有baozhuangdaima的记录,不要可注释掉 and isnull(a.baozhuangmingcheng,'') in ('ZX','ZH') update BZDM set baozhuangdaima = b.baozhuangmingcheng from BZDM a, deleted b where a.baozhuangID = b.baozhuangID --and isnull(a.baozhuangdaima,'') = ''--只修改没有baozhuangdaima的记录,不要可注释掉 and isnull(a.baozhuangmingcheng,'') not in ('ZX','ZH') END