﻿DROP PROCEDURE IF EXISTS uspOktAzon4TAlapjanFollowUp
GO
 
CREATE PROCEDURE uspOktAzon4TAlapjanFollowUp
   @pCheckValidationType int
  ,@pEntityId int
  ,@pAnotherTanevEntityId int
AS
BEGIN
  SET NOCOUNT ON;
  IF (NOT EXISTS (SELECT TOP 1 1 FROM T_FELHASZNALO_OSSZES WHERE ELOZOTANEVIREKORDID IN (@pEntityId, @pAnotherTanevEntityId) AND TOROLT = 'F')) /* meg nincs followupolva*/
  BEGIN
    DECLARE @intezmenyId int, @isAktivTanevEntity char(1)
    SELECT 
       @isAktivTanevEntity = t.C_AKTIV
      ,@intezmenyId = t.C_INTEZMENYID
    FROM T_FELHASZNALO_OSSZES fh 
    INNER JOIN T_TANEV_OSSZES t ON  t.ID = fh.C_TANEVID AND t.TOROLT = 'F' 
    WHERE fh.ID = @pEntityId

    DECLARE @aktTanevId int = (SELECT ID FROM T_TANEV_OSSZES WHERE C_INTEZMENYID = @intezmenyId AND C_AKTIV = 'T' AND TOROLT = 'F'), 
            @kovTanevId int = (SELECT ID FROM T_TANEV_OSSZES WHERE C_INTEZMENYID = @intezmenyId AND C_KOVETKEZO = 'T' AND TOROLT = 'F')

    /*kozos entitasok*/
    /*T_FELHASZNALO*/
    UPDATE T_FELHASZNALO_OSSZES
    SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @pEntityId, @pAnotherTanevEntityId) 
    WHERE ID = IIF(@isAktivTanevEntity = 'T', @pAnotherTanevEntityId, @pEntityId) AND TOROLT = 'F'

    IF @isAktivTanevEntity = 'F'
    BEGIN
      UPDATE T_FELHASZNALO_OSSZES
      SET C_IDPEGYEDIAZONOSITO = (SELECT C_IDPEGYEDIAZONOSITO FROM T_FELHASZNALO_OSSZES WHERE ID = @pAnotherTanevEntityId)
      WHERE ID = @pEntityId
    END
    
    /*T_CIM*/    
    DECLARE @cimId int = (SELECT TOP 1 ID FROM T_CIM_OSSZES WHERE C_FELHASZNALOID = @pEntityId AND TOROLT = 'F' ORDER BY C_ALAPERTELMEZETT DESC), 
            @anotherCimId int = (SELECT TOP 1 ID FROM T_CIM_OSSZES WHERE C_FELHASZNALOID = @pAnotherTanevEntityId AND TOROLT = 'F' ORDER BY C_ALAPERTELMEZETT DESC)

    IF (@isAktivTanevEntity = 'F' AND @anotherCimId IS NOT NULL AND @cimId IS NULL)
      EXEC uspFollowUpFelhasznaloCim @intezmenyId,@aktTanevId,@kovTanevId,@pAnotherTanevEntityId
    ELSE
      UPDATE T_CIM_OSSZES
      SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @cimId, @anotherCimId) 
      WHERE C_GONDVISELOID IS NULL AND ID = IIF(@isAktivTanevEntity = 'T', @anotherCimId, @cimId) AND TOROLT = 'F'

    /*T_EMAIL*/
    DECLARE @emailId int = (SELECT TOP 1 ID FROM T_EMAIL_OSSZES WHERE C_FELHASZNALOID = @pEntityId AND TOROLT = 'F' ORDER BY C_ALAPERTELMEZETT DESC), 
            @anotherEmailId int = (SELECT TOP 1 ID FROM T_EMAIL_OSSZES WHERE C_FELHASZNALOID = @pAnotherTanevEntityId AND TOROLT = 'F' ORDER BY C_ALAPERTELMEZETT DESC)

    IF (@isAktivTanevEntity = 'F' AND @anotherEmailId IS NOT NULL AND @emailId IS NULL)
      EXEC uspFollowUpFelhasznaloEmail @intezmenyId,@aktTanevId,@kovTanevId,@pAnotherTanevEntityId
    ELSE
      UPDATE T_EMAIL_OSSZES
      SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @emailId, @anotherEmailId) 
      WHERE C_GONDVISELOID IS NULL AND ID = IIF(@isAktivTanevEntity = 'T', @anotherEmailId, @emailId) AND TOROLT = 'F'

    /*T_TELEFON*/
    DECLARE @telefonId int = (SELECT TOP 1 ID FROM T_TELEFON_OSSZES WHERE C_FELHASZNALOID = @pEntityId AND TOROLT = 'F' ORDER BY C_ALAPERTELMEZETT DESC), 
            @anotherTelefonId int = (SELECT TOP 1 ID FROM T_TELEFON_OSSZES WHERE C_FELHASZNALOID = @pAnotherTanevEntityId AND TOROLT = 'F' ORDER BY C_ALAPERTELMEZETT DESC)

    IF (@isAktivTanevEntity = 'F' AND @anotherTelefonId IS NOT NULL AND @telefonId IS NULL)
      EXEC uspFollowUpFelhasznaloTelefon @intezmenyId,@aktTanevId,@kovTanevId,@pAnotherTanevEntityId
    ELSE
      UPDATE T_TELEFON_OSSZES
      SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @telefonId, @anotherTelefonId) 
      WHERE C_GONDVISELOID IS NULL AND ID = IIF(@isAktivTanevEntity = 'T', @anotherTelefonId, @telefonId) AND TOROLT = 'F'

    IF(@pCheckValidationType = 1) /* 1 - Tanuló */
    BEGIN
      /*T_TANULO*/
      UPDATE T_TANULO_OSSZES SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @pEntityId, @pAnotherTanevEntityId) 
      WHERE ID = IIF(@isAktivTanevEntity = 'T', @pAnotherTanevEntityId, @pEntityId) AND TOROLT = 'F'

      /*T_TANULOMENTESSEG*/
      DECLARE @tanuloMentessegId int = (SELECT TOP 1 ID FROM T_TANULOMENTESSEG_OSSZES WHERE C_TANULOID = @pEntityId AND TOROLT = 'F'), 
              @anotherTanuloMentessegId int = (SELECT TOP 1 ID FROM T_TANULOMENTESSEG_OSSZES WHERE C_TANULOID = @pAnotherTanevEntityId AND TOROLT = 'F')

      IF (@isAktivTanevEntity = 'F' AND @anotherTanuloMentessegId IS NOT NULL AND @tanuloMentessegId IS NULL)
        EXEC uspFollowUpTanuloFelmentes @intezmenyId,@aktTanevId,@kovTanevId,@anotherTanuloMentessegId
      ELSE
        UPDATE T_TANULOMENTESSEG_OSSZES
        SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @tanuloMentessegId, @anotherTanuloMentessegId) 
        WHERE ID = IIF(@isAktivTanevEntity = 'T', @anotherTanuloMentessegId, @tanuloMentessegId) AND TOROLT = 'F'

      /*T_TANULOSNI*/
      DECLARE @tanuloSNIId int = (SELECT TOP 1 ID FROM T_TANULOSNI_OSSZES WHERE C_TANULOID = @pEntityId AND TOROLT = 'F'), 
              @anotherTanulSNIId int = (SELECT TOP 1 ID FROM T_TANULOSNI_OSSZES WHERE C_TANULOID = @pAnotherTanevEntityId AND TOROLT = 'F')

      IF (@isAktivTanevEntity = 'F' AND @anotherTanulSNIId IS NOT NULL AND @tanuloSNIId IS NULL)
        EXEC uspFollowUpTanuloSni @intezmenyId,@aktTanevId,@kovTanevId,@anotherTanulSNIId
      ELSE
        UPDATE T_TANULOSNI_OSSZES
        SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @tanuloSNIId, @anotherTanulSNIId) 
        WHERE ID = IIF(@isAktivTanevEntity = 'T', @anotherTanulSNIId, @tanuloSNIId) AND TOROLT = 'F'

      /*T_TBJOGVISZONY*/
      EXEC uspFollowUpTBJogviszony @intezmenyId, @aktTanevId, @kovTanevId, @pEntityId

    END
    ELSE IF (@pCheckValidationType = 2) /* 2 - Alkalmazott */
    BEGIN
      /*T_ALKALMAZOTT*/
      UPDATE T_ALKALMAZOTT_OSSZES
      SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @pEntityId, @pAnotherTanevEntityId) 
      WHERE ID = IIF(@isAktivTanevEntity = 'T', @pAnotherTanevEntityId, @pEntityId) AND TOROLT = 'F'

      /*T_MUNKAUGYIADATOK*/
      DECLARE @munkaugyiadatokId int = (SELECT TOP 1 ID FROM T_MUNKAUGYIADATOK_OSSZES WHERE C_ALKALMAZOTTID = @pEntityId AND TOROLT = 'F'), 
            @anotherMunkaugyiadatokId int = (SELECT TOP 1 ID FROM T_MUNKAUGYIADATOK_OSSZES WHERE C_ALKALMAZOTTID = @pAnotherTanevEntityId AND TOROLT = 'F')

      UPDATE T_MUNKAUGYIADATOK_OSSZES
      SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T',@munkaugyiadatokId, @anotherMunkaugyiadatokId) 
      WHERE ID = IIF(@isAktivTanevEntity = 'T', @anotherMunkaugyiadatokId, @munkaugyiadatokId) AND TOROLT = 'F'

      /*Vegzettseg*/
      IF ((SELECT ic.C_ERTEK FROM T_INTEZMENYCONFIG ic WHERE ic.C_CONFIGTIPUSID = 23 AND ic.TOROLT = 'F' AND ic.C_INTEZMENYID = @intezmenyId) = 'true')
        BEGIN
        DECLARE @KKTANITOVEZGETTSEGId int = (SELECT TOP 1 ID FROM T_KKTANITOVEZGETTSEG_OSSZES WHERE C_ALKALMAZOTTID = @pEntityId AND TOROLT = 'F'), 
                @anotherKKTANITOVEZGETTSEGId int = (SELECT TOP 1 ID FROM T_KKTANITOVEZGETTSEG_OSSZES WHERE C_ALKALMAZOTTID = @pAnotherTanevEntityId AND TOROLT = 'F')

        IF (@isAktivTanevEntity = 'F' AND @anotherKKTANITOVEZGETTSEGId IS NOT NULL AND @KKTANITOVEZGETTSEGId IS NULL)
          EXEC uspFollowUpAlkalmazottVegzettsegKK @intezmenyId,@aktTanevId,@kovTanevId,@pAnotherTanevEntityId
        ELSE
          BEGIN
          /*T_KKTANITOVEZGETTSEG*/
          UPDATE T_KKTANITOVEZGETTSEG_OSSZES
          SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @KKTANITOVEZGETTSEGId, @anotherKKTANITOVEZGETTSEGId) 
          WHERE ID = IIF(@isAktivTanevEntity = 'T', @anotherKKTANITOVEZGETTSEGId, @KKTANITOVEZGETTSEGId) AND TOROLT = 'F'

          /*T_KKGYOGYPEDVEGZETTSEG*/
          DECLARE @KKGYOGYPEDVEGZETTSEGId int = (SELECT TOP 1 ID FROM T_KKGYOGYPEDVEGZETTSEG_OSSZES WHERE C_ALKALMAZOTTID = @pEntityId AND TOROLT = 'F'), 
                  @anotherKKGYOGYPEDVEGZETTSEGId int = (SELECT TOP 1 ID FROM T_KKGYOGYPEDVEGZETTSEG_OSSZES WHERE C_ALKALMAZOTTID = @pAnotherTanevEntityId AND TOROLT = 'F')

          UPDATE T_KKGYOGYPEDVEGZETTSEG_OSSZES
          SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @KKGYOGYPEDVEGZETTSEGId, @anotherKKGYOGYPEDVEGZETTSEGId) 
          WHERE ID = IIF(@isAktivTanevEntity = 'T', @anotherKKGYOGYPEDVEGZETTSEGId, @KKGYOGYPEDVEGZETTSEGId) AND TOROLT = 'F'

          /*T_KKTANARVEGZETTSEG*/
          DECLARE @KKTANARVEGZETTSEGId int = (SELECT TOP 1 ID FROM T_KKTANARVEGZETTSEG_OSSZES WHERE C_ALKALMAZOTTID = @pEntityId AND TOROLT = 'F'), 
                  @anotherKKTANARVEGZETTSEGId int = (SELECT TOP 1 ID FROM T_KKTANARVEGZETTSEG_OSSZES WHERE C_ALKALMAZOTTID = @pAnotherTanevEntityId AND TOROLT = 'F')

          UPDATE T_KKTANARVEGZETTSEG_OSSZES
          SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @KKTANARVEGZETTSEGId, @anotherKKTANARVEGZETTSEGId) 
          WHERE ID = IIF(@isAktivTanevEntity = 'T', @anotherKKTANARVEGZETTSEGId, @KKTANARVEGZETTSEGId) AND TOROLT = 'F'

          /*T_KKTANTARGYKATEGORIA*/
          DECLARE @KKTANTARGYKATEGORIAId int = (SELECT TOP 1 ID FROM T_KKTANTARGYKATEGORIA_OSSZES WHERE C_KKTANARVEGZETTSEGID = @KKTANARVEGZETTSEGId AND TOROLT = 'F'), 
                  @anotherKKTANTARGYKATEGORIAId int = (SELECT TOP 1 ID FROM T_KKTANTARGYKATEGORIA_OSSZES WHERE C_KKTANARVEGZETTSEGID = @anotherKKTANARVEGZETTSEGId AND TOROLT = 'F')

          UPDATE T_KKTANTARGYKATEGORIA_OSSZES
          SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @KKTANTARGYKATEGORIAId, @anotherKKTANTARGYKATEGORIAId) 
          WHERE ID = IIF(@isAktivTanevEntity = 'T', @anotherKKTANTARGYKATEGORIAId, @KKTANTARGYKATEGORIAId) AND TOROLT = 'F'

          /*T_KKAMIVEGZETTSEG*/
          DECLARE @KKAMIVEGZETTSEGId int = (SELECT TOP 1 ID FROM T_KKAMIVEGZETTSEG_OSSZES WHERE C_ALKALMAZOTTID = @pEntityId AND TOROLT = 'F'), 
                  @anotherKKAMIVEGZETTSEGId int = (SELECT TOP 1 ID FROM T_KKAMIVEGZETTSEG_OSSZES WHERE C_ALKALMAZOTTID = @pAnotherTanevEntityId AND TOROLT = 'F')

          UPDATE T_KKAMIVEGZETTSEG_OSSZES
          SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @KKAMIVEGZETTSEGId, @anotherKKAMIVEGZETTSEGId) 
          WHERE ID = IIF(@isAktivTanevEntity = 'T', @anotherKKAMIVEGZETTSEGId, @KKAMIVEGZETTSEGId) AND TOROLT = 'F'

          /*T_KKELEKTROAKUZENE*/
          DECLARE @KKELEKTROAKUZENEId int = (SELECT TOP 1 ID FROM T_KKELEKTROAKUZENE_OSSZES WHERE C_KKAMIVEGZETTSEGID = @KKAMIVEGZETTSEGId AND TOROLT = 'F'), 
              @anotherKKELEKTROAKUZENEId int = (SELECT TOP 1 ID FROM T_KKELEKTROAKUZENE_OSSZES WHERE C_KKAMIVEGZETTSEGID = @anotherKKAMIVEGZETTSEGId AND TOROLT = 'F')

          UPDATE T_KKELEKTROAKUZENE_OSSZES
          SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @KKELEKTROAKUZENEId, @anotherKKELEKTROAKUZENEId) 
          WHERE ID = IIF(@isAktivTanevEntity = 'T', @anotherKKELEKTROAKUZENEId, @KKELEKTROAKUZENEId) AND TOROLT = 'F'

          /*T_KKKLASSZIKUSZENE*/
          DECLARE @KKKLASSZIKUSZENEId int = (SELECT TOP 1 ID FROM T_KKKLASSZIKUSZENE_OSSZES WHERE C_KKAMIVEGZETTSEGID = @KKAMIVEGZETTSEGId AND TOROLT = 'F'), 
                  @anotherKKKLASSZIKUSZENEId int = (SELECT TOP 1 ID FROM T_KKKLASSZIKUSZENE_OSSZES WHERE C_KKAMIVEGZETTSEGID = @anotherKKAMIVEGZETTSEGId AND TOROLT = 'F')

          UPDATE T_KKKLASSZIKUSZENE_OSSZES
          SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @KKKLASSZIKUSZENEId, @anotherKKKLASSZIKUSZENEId) 
          WHERE ID = IIF(@isAktivTanevEntity = 'T', @anotherKKKLASSZIKUSZENEId, @KKKLASSZIKUSZENEId) AND TOROLT = 'F'

          /*T_KKNEPZENE*/
          DECLARE @KKNEPZENEId int = (SELECT TOP 1 ID FROM T_KKNEPZENE_OSSZES WHERE C_KKAMIVEGZETTSEGID = @KKAMIVEGZETTSEGId AND TOROLT = 'F'), 
                  @anotherKKNEPZENEId int = (SELECT TOP 1 ID FROM T_KKNEPZENE_OSSZES WHERE C_KKAMIVEGZETTSEGID = @anotherKKAMIVEGZETTSEGId AND TOROLT = 'F')

          UPDATE T_KKNEPZENE_OSSZES
          SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @KKNEPZENEId, @anotherKKNEPZENEId) 
          WHERE ID = IIF(@isAktivTanevEntity = 'T', @anotherKKNEPZENEId, @KKNEPZENEId) AND TOROLT = 'F'

          /*T_KKJAZZZENE*/
          DECLARE @KKJAZZZENEId int = (SELECT TOP 1 ID FROM T_KKJAZZZENE_OSSZES WHERE C_KKAMIVEGZETTSEGID = @KKAMIVEGZETTSEGId AND TOROLT = 'F'), 
                  @anotherKKJAZZZENEId int = (SELECT TOP 1 ID FROM T_KKJAZZZENE_OSSZES WHERE C_KKAMIVEGZETTSEGID = @anotherKKAMIVEGZETTSEGId AND TOROLT = 'F')

          UPDATE T_KKJAZZZENE_OSSZES
          SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @KKJAZZZENEId, @anotherKKJAZZZENEId) 
          WHERE ID = IIF(@isAktivTanevEntity = 'T', @anotherKKJAZZZENEId, @KKJAZZZENEId) AND TOROLT = 'F'

          /*T_KKTERULET*/
          DECLARE @KKTERULETId int = (SELECT TOP 1 ID FROM T_KKTERULET_OSSZES WHERE C_KKAMIVEGZETTSEGID = @KKAMIVEGZETTSEGId AND TOROLT = 'F'), 
              @anotherKKTERULETId int = (SELECT TOP 1 ID FROM T_KKTERULET_OSSZES WHERE C_KKAMIVEGZETTSEGID = @anotherKKAMIVEGZETTSEGId AND TOROLT = 'F')
          UPDATE T_KKTERULET_OSSZES
          SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @KKTERULETId, @anotherKKTERULETId) 
          WHERE ID = IIF(@isAktivTanevEntity = 'T', @anotherKKTERULETId, @KKTERULETId) AND TOROLT = 'F'
          END
      END
      ELSE BEGIN
        /*T_VEGZETTSEG*/
        DECLARE @VEGZETTSEGId int = (SELECT TOP 1 ID FROM T_VEGZETTSEG_OSSZES WHERE C_TANARID = @pEntityId AND TOROLT = 'F'), 
                @anotherVEGZETTSEGId int = (SELECT TOP 1 ID FROM T_VEGZETTSEG_OSSZES WHERE C_TANARID = @pAnotherTanevEntityId AND TOROLT = 'F')

        IF (@isAktivTanevEntity = 'F' AND @anotherVEGZETTSEGId IS NOT NULL AND @VEGZETTSEGId IS NULL)
          EXEC uspFollowUpAlkalmazottVegzettseg @intezmenyId,@aktTanevId,@kovTanevId,@anotherVEGZETTSEGId
        ELSE
          UPDATE T_VEGZETTSEG_OSSZES
          SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @VEGZETTSEGId, @anotherVEGZETTSEGId) 
          WHERE ID = IIF(@isAktivTanevEntity = 'T', @anotherVEGZETTSEGId, @VEGZETTSEGId) AND TOROLT = 'F'        
      END

      /*T_PEDAGOGUSELETPALYAMODELL*/
      DECLARE @eletpalyaModellId int = (SELECT TOP 1 ID FROM T_PEDAGOGUSELETPALYAMODELL_OSSZES WHERE C_TANARID = @pEntityId AND TOROLT = 'F'), 
              @anotherEletpalyaModellId int = (SELECT TOP 1 ID FROM T_PEDAGOGUSELETPALYAMODELL_OSSZES WHERE C_TANARID = @pAnotherTanevEntityId AND TOROLT = 'F')

      IF (@isAktivTanevEntity = 'F' AND @anotherEletpalyaModellId IS NOT NULL AND @eletpalyaModellId IS NULL)
        EXEC uspFollowUpAlkalmazottPEP @intezmenyId,@aktTanevId,@kovTanevId,@anotherEletpalyaModellId
      ELSE
        UPDATE T_PEDAGOGUSELETPALYAMODELL_OSSZES
        SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @eletpalyaModellId, @anotherEletpalyaModellId) 
        WHERE ID = IIF(@isAktivTanevEntity = 'T', @anotherEletpalyaModellId, @eletpalyaModellId) AND TOROLT = 'F'

      /*T_TOVABBIMUNKAUGYIADATOK*/
      DECLARE @TOVABBIMUNKAUGYIADATOKId int = (SELECT TOP 1 ID FROM T_TOVABBIMUNKAUGYIADATOK_OSSZES WHERE C_ALKALMAZOTTID = @pEntityId AND TOROLT = 'F'), 
              @anotherTOVABBIMUNKAUGYIADATOKId int = (SELECT TOP 1 ID FROM T_TOVABBIMUNKAUGYIADATOK_OSSZES WHERE C_ALKALMAZOTTID = @pAnotherTanevEntityId AND TOROLT = 'F')

      IF (@isAktivTanevEntity = 'F' AND @anotherTOVABBIMUNKAUGYIADATOKId IS NOT NULL AND @TOVABBIMUNKAUGYIADATOKId IS NULL)
        EXEC uspFollowUpAlkalmazottTovabbiMunkaugy @intezmenyId,@aktTanevId,@kovTanevId,@anotherTOVABBIMUNKAUGYIADATOKId
      ELSE
        UPDATE T_TOVABBIMUNKAUGYIADATOK_OSSZES
        SET ELOZOTANEVIREKORDID = IIF(@isAktivTanevEntity = 'T', @TOVABBIMUNKAUGYIADATOKId, @anotherTOVABBIMUNKAUGYIADATOKId) 
        WHERE ID = IIF(@isAktivTanevEntity = 'T', @anotherTOVABBIMUNKAUGYIADATOKId, @TOVABBIMUNKAUGYIADATOKId) AND TOROLT = 'F'
    END
  END
END
GO