DROP PROCEDURE IF EXISTS dev.uspDropSchemaAndOthers
GO

CREATE PROCEDURE dev.uspDropSchemaAndOthers
  @pIntezmenyAzonositok nvarchar(500)
AS
BEGIN
  DECLARE @schemaName nvarchar(100)
    ,@message nvarchar(200)
  
  DECLARE intCursor CURSOR FAST_FORWARD READ_ONLY FOR 
  SELECT 'KR_' + LTRIM(RTRIM(ss.value)) + '_Schema'
  FROM STRING_SPLIT(@pIntezmenyAzonositok, ',') ss
  
  OPEN intCursor
  
  FETCH NEXT FROM intCursor 
  INTO @schemaName
  
  WHILE @@FETCH_STATUS = 0 BEGIN
    SET @message = 'Drop spfn - ' + @schemaName
    RAISERROR (@message, 10, 1) WITH NOWAIT 
    EXEC dev.uspDropSchemaSPFN NULL, @schemaName

    SET @message = 'Drop view - ' + @schemaName
    RAISERROR (@message, 10, 1) WITH NOWAIT 
    EXEC dev.uspDropSchemaViews NULL, @schemaName

    SET @message = 'Drop schema - ' + @schemaName
    RAISERROR (@message, 10, 1) WITH NOWAIT 
    EXEC dev.uspDropSchema @schemaName

    FETCH NEXT FROM intCursor 
    INTO @schemaName
  END
  
  CLOSE intCursor
  DEALLOCATE intCursor

END
GO