-- dbo.ET_TabPrikazMzdyAZmetky_HDC_D
CREATE TRIGGER dbo.ET_TabPrikazMzdyAZmetky_HDC_D ON dbo.TabPrikazMzdyAZmetky
WITH EXECUTE AS CALLER
FOR DELETE
AS
BEGIN
 SET NOCOUNT ON

-- !! trigger neupravujte, bude stejne pregenerovan pri startu pluginu PluginHDCRTN nebo Windows sluzby HDCDZApi !!

 DECLARE
  @id INT



 DECLARE c CURSOR LOCAL FAST_FORWARD FOR
  SELECT d.ID
   FROM deleted d
 OPEN c
 WHILE (1=1)
  BEGIN
   FETCH NEXT FROM c INTO @id
   IF (@@FETCH_STATUS<>0) BREAK

-- sync informace pro reseni ASol/ProHolding/HDC
-- vydejky
   IF OBJECT_ID(N'dbo._hdc_ph_PrijataJsonData', N'U') IS NOT NULL
    UPDATE dbo._hdc_ph_PrijataJsonData SET IDMzda=NULL WHERE IDMzda=@id

  END
 CLOSE c
 DEALLOCATE c

END
