USE [tisnet]
GO

/****** Object:  Trigger [AktualizaceDorucenkyTISu]    Script Date: 03/18/2010 09:16:01 ******/
IF  EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[Spisovka].[AktualizaceDorucenkyTISu]'))
DROP TRIGGER [Spisovka].[AktualizaceDorucenkyTISu]
GO

USE [tisnet]
GO

/****** Object:  Trigger [Spisovka].[AktualizaceDorucenkyTISu]    Script Date: 03/18/2010 09:16:01 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TRIGGER [Spisovka].[AktualizaceDorucenkyTISu] ON [Spisovka].[Zasilka] AFTER UPDATE AS BEGIN SET NOCOUNT ON;DECLARE @dmID varchar(20) DECLARE @Poznamka nvarchar(255) DECLARE @DatumDoruceni datetime DECLARE @StavZasilky smallint DECLARE @ID uniqueidentifier SELECT @dmID=dmID, @Poznamka=Poznamka, @DatumDoruceni = DatumDOruceni, @StavZasilky = Stav, @Id = Id FROM inserted UPDATE topeko.dbo.sssezsub SET dmID=@dmID, dorpozn=@Poznamka, datdor=@DatumDoruceni, sto=@StavZasilky WHERE guid_sssezsub=@Id END;
GO

--Aktualizace poznamky
UPDATE topeko.dbo.sssezsub SET dorPozn=(select Poznamka from tisnet.Spisovka.Zasilka z where guid_sssezsub=z.id) WHERE guid_sssezsub in (select id from tisnet.Spisovka.Zasilka where Poznamka is not null) and zpz=440 and zpo=40
--Aktualizace cisla zpravy dmID
UPDATE topeko.dbo.sssezsub SET dmID=(select dmID from tisnet.Spisovka.Zasilka z where guid_sssezsub=z.id) WHERE guid_sssezsub in (select id from tisnet.Spisovka.Zasilka where dmID is not null) and zpz=440 and zpo=40
--Aktualizace stavu zasilky
UPDATE topeko.dbo.sssezsub SET sto=(select Stav from tisnet.Spisovka.Zasilka z where guid_sssezsub=z.id) WHERE guid_sssezsub in (select id from tisnet.Spisovka.Zasilka where Stav is not null) and zpz=440 and zpo=40
--Aktualizace data doruceni
UPDATE topeko.dbo.sssezsub SET datdor=(select DatumDoruceni from tisnet.Spisovka.Zasilka z where guid_sssezsub=z.id) WHERE guid_sssezsub in (select id from tisnet.Spisovka.Zasilka where DatumDoruceni is not null) and zpz=440 and zpo=40



