SQL Server trigger----and delete trigger, two tables

Source: Internet
Author: User

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 = ' No '


 if exists (select 1 from inserted)
  begin
  select @SaleShop =saleshop from Inserted
  select @minDfJjSale =min (dfjjsale), @maxDfJjSale =max (Dfjjsale) from Tab_saleandcarstyle where [Email protected] and state>0 and Price_ver=1 Group by Saleshop
     & Nbsp;if (@minDfJjSale =0 and @maxDfJjSale =0)
   set @isDfjj = ' no '
   else
   set @isDfjj = ' is '
   update dbo. TAB_PARTNER &NBSP,
   set Pricerange=ltrim (@minDfJjSale) + ' ~ ' +ltrim (@maxDfJjSale), [email  protected]
   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 [email protected] and State>0 and Price_ver=1 GROUP by Saleshop
if (@minDfJjSale =0 and @maxDfJjSale =0)
Set @isDfjj = ' No '
Else
Set @isDfjj = ' Yes '
UPDATE dbo. Tab_partner
Set Pricerange=ltrim (@minDfJjSale) + ' ~ ' +ltrim (@maxDfJjSale), [email protected]
where id= @saleshop
END

SQL Server trigger----and delete trigger, two tables

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.