Advertisement
piotrek77

TRIGGER [CDN].[TraElem_AFRabatDok]

Oct 30th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 3.23 KB | None | 0 0
  1. USE [CDNXL_ASXSASD]
  2. GO
  3. /****** Object:  Trigger [CDN].[TraElem_AFRabatDok]    Script Date: 10/30/2012 10:26:30 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. -- =============================================
  9. -- Author:      <Author,,Name>
  10. -- Create date: <Create Date,,>
  11. -- Description: <Description,,>
  12. -- =============================================
  13. ALTER TRIGGER [CDN].[TraElem_AFRabatDok]
  14.    ON  [CDN].[TraElem]
  15.    AFTER UPDATE
  16. AS
  17. BEGIN
  18.  
  19.  
  20.     --treść skopiowana z triggera z CDN.TraNag AFRabatDok
  21.    
  22.     -- SET NOCOUNT ON added to prevent extra result sets from
  23.     -- interfering with SELECT statements.
  24.     SET NOCOUNT ON;
  25.  
  26. if update(tre_rabat)
  27.  
  28.  
  29.     begin
  30.  
  31.  
  32.  
  33. --@idAtr - atrybut z wartoscia rabatu
  34. --@RabatMin - w przypadku braku rabatu na operatorze, ta wartosc jest dopuszczalna
  35. --@RabatCheck - jesli ma wartosc 'TAK' na karcie towarowej pozycji kontrola rabatu na tej pozycji nie działa
  36. declare @idAtr int
  37.  
  38. declare @RabatMin decimal(5,2)
  39. declare @RabatOper decimal(5,2)
  40. declare @RabatCheck int
  41.  
  42.  
  43. set @IdAtr=1015 --!!!Tu id atrybutu operatora
  44. set @RabatCheck=1016
  45. set @RabatMin=5.2
  46.  
  47.  
  48.     if  
  49.      exists
  50.     (select * from inserted INS
  51.     JOIN cdn.TraNag as TRN on INS.TrE_GIDTyp = TRN.TrN_GIDTyp AND INS.TrE_GIDNumer = TRN.TrN_GIDNumer
  52.     --join deleted DEL on DEL.trn_gidnumer=INS.trn_gidnumer
  53.     where ins.tre_gidtyp in (2001,2033,2034) )
  54.     --and TRN.trN_stan>2 and TRN.trn_stan<>6 and del.trn_stan<=2)
  55.  
  56.  
  57.  
  58.         Begin
  59.     set @RabatOper =isnull((select cast(isnull(atr_wartosc,@RabatMin) as decimal(5,2)) from inserted as INS
  60. JOIN cdn.TraNag as TRN on INS.TrE_GIDTyp = TRN.TrN_GIDTyp AND INS.TrE_GIDNumer = TRN.TrN_GIDNumer  
  61.                 join cdn.atrybuty on atr_obityp=trn_opetypm and atr_obinumer=TrN_OpeNumerM and atr_atkid=@IdAtr),@RabatMin)
  62.  
  63.  
  64.  
  65.  
  66.             if exists(select * from inserted as INS
  67.         JOIN cdn.TraNag as TRN on INS.TrE_GIDTyp = TRN.TrN_GIDTyp AND INS.TrE_GIDNumer = TRN.TrN_GIDNumer
  68.         join cdn.twrkarty on twr_gidnumer=tre_twrnumer
  69.         left join cdn.atrybuty on atr_obityp=twr_gidtyp and atr_obinumer=twr_gidnumer and atr_atkid=@RabatCheck
  70.         where tre_rabat>@RabatOper and isnull(atr_wartosc,'')<>'TAK' and TrE_CenaSpr=3
  71.     AND (Right(IsNull(TRN.TrN_TrnSeria,''),2)<>'RE')    )
  72.    
  73.             AND
  74.            
  75.     --tu ma być tru jeśli w cechach na dostawie znajdę cokolwiek niż ODCIN
  76.             Exists (select * from inserted
  77. JOIN CDN.TraSElem
  78. ON TrE_GIDTyp=TrS_GIDTyp AND TrE_GIDNumer=TrS_GIDNumer AND TrE_GIDLp=TrS_GIDLp
  79. JOIN CDN.Dostawy
  80. ON Dst_GIDNumer=TrS_DstNumer
  81. where
  82. Left(Dst_Cecha,5) <> 'ODCIN')          
  83.    
  84.        
  85.             Begin
  86.  
  87. declare @komunikat1 varchar(500)
  88. set @komunikat1='#CDN_INFO/# #CDN_1=Przekroczony rabat na pozycji '
  89. --+
  90. --(select  min(cast(tre_pozycja as varchar(4))) from inserted
  91. --                      join cdn.traelem (nolock) on tre_gidnumer=trn_gidnumer
  92. --  join cdn.twrkarty on twr_gidnumer=tre_twrnumer
  93. --      left join.atrybuty on atr_obityp=twr_gidtyp and atr_obinumer=twr_gidnumer and atr_atkid=@RabatCheck
  94. --      where tre_rabat>@RabatOper and isnull(atr_wartosc,'')<>'TAK' and TrE_CenaSpr=3)
  95.                    
  96. +
  97. '!/# #CDN_2=Twój max.rabat to '
  98. +
  99. cast(@RabatOper as varchar(5))
  100. +
  101. '/# #CDN_3=Zmniejsz rabat /#'      
  102.  
  103.         raiserror(@komunikat1,16,1)
  104.              ROLLBACK TRAN
  105.                 SET NOCOUNT ON
  106.                  RETURN
  107.     end
  108.     end
  109.     end
  110.  
  111.  
  112.  
  113. SET NOCOUNT OFF
  114.  
  115. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement