欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

SQLServer 触发器

程序员文章站 2022-06-01 14:23:14
...

ALTER TRIGGER [dbo].[PriceRange] ON[dbo].[Tab_SaleAndCarStyle] for update,insert,delete AS declare @Saleshop int,@minDfJjSale decimal(18,3),@maxDfJjSale decimal(18,3),@isDfjj varchar(50) set @isDfjj='否' if exists(select 1 from inserted) B

ALTER TRIGGER [dbo].[PriceRange]
ON [dbo].[Tab_SaleAndCarStyle]
for update,insert,delete
AS
declare @Saleshop int,@minDfJjSale decimal(18,3),@maxDfJjSale decimal(18,3),@isDfjj varchar(50)
set @isDfjj='否'


if exists(select 1 from inserted)
BEGIN
select @SaleShop=SaleShop from inserted
select @minDfJjSale=min(DfJjSale),@maxDfJjSale=max(DfJjSale) from Tab_SaleAndCarStyle where Saleshop=@Saleshop and state>0 and price_ver=1 group by SaleShop
if(@minDfJjSale=0 and @maxDfJjSale=0)
set @isDfjj='否'
else
set @isDfjj='是'
update dbo.TAB_PARTNER
set PriceRange=ltrim(@minDfJjSale)+'~'+ltrim(@maxDfJjSale),ispartneraddprice=@isDfjj
where ID= @saleshop
END

else
if exists (select 1 from deleted)
BEGIN
select @SaleShop=SaleShop from deleted
select @minDfJjSale=min(DfJjSale),@maxDfJjSale=max(DfJjSale) from Tab_SaleAndCarStyle where Saleshop=@Saleshop and state>0 and price_ver=1 group by SaleShop
if(@minDfJjSale=0 and @maxDfJjSale=0)
set @isDfjj='否'
else
set @isDfjj='是'
update dbo.TAB_PARTNER
set PriceRange=ltrim(@minDfJjSale)+'~'+ltrim(@maxDfJjSale),ispartneraddprice=@isDfjj
where ID= @saleshop
END