﻿DROP PROCEDURE IF EXISTS [dbo].[sp_CheckOktatasiAzonositoUtkozesValidation]
GO

CREATE PROCEDURE [dbo].[sp_CheckOktatasiAzonositoUtkozesValidation]
  @pNebuloId AS INT = NULL,
  @pFelvetelStatusza INT = NULL,
  @pOktatasiAzonosito NVARCHAR(20)
AS
BEGIN
  SET NOCOUNT ON;

  IF (@pFelvetelStatusza IS NULL)
      IF 
      EXISTS  (SELECT 1
           FROM 
            T_NEBULO
           WHERE 
              TOROLT = 'F'
            AND (@pNebuloId IS NULL OR ID != @pNebuloId)            
            AND C_OKTATASIAZONOSITOSZAMA = @pOktatasiAzonosito
          )
        
      SELECT 1
    ELSE
      SELECT 0

  ELSE
      IF 
      EXISTS  (SELECT 1
           FROM 
            T_NEBULO
           WHERE 
              TOROLT = 'F'
            AND (@pNebuloId IS NULL OR ID != @pNebuloId)
            AND C_FELVETELSTATUSZA = @pFelvetelStatusza
            AND C_OKTATASIAZONOSITOSZAMA = @pOktatasiAzonosito
          )
        
      SELECT 1
    ELSE
      SELECT 0
      
END
GO
