SQLServer 触发器
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
推荐阅读
-
浅谈SQLServer的ISNULL函数与Mysql的IFNULL函数用法详解
-
解析SQLServer2005的Top功能
-
sqlserver 不能将值NULL插入列id(列不允许有空值解决)
-
解析如何在sqlserver代理中配置邮件会话
-
sqlServer使用ROW_NUMBER时不排序的解决方法
-
sqlserver中获取date类的年月日语句
-
sqlserver 使用SSMS运行sql脚本的六种方法
-
深入SQLServer中ISNULL与NULLIF的使用详解
-
SQLServer:探讨EXEC与sp_executesql的区别详解
-
SQLServer2000 报1053错误(服务没有及时响应或控制请求)的解决方法