-- -----------------------------------------------------------------------------
-- SHC Software GmbH
-- Copyright (c) 2014 - 2017
--
-- SHC Mobile (SHC8Mobile_Drop_Database_Views_and_SP_2016)
--
-- Encoding must be Windows-1252 ANSI NOT UTF8
--
-- $Id:$
--
-- @author  infoMantis GmbH
-- @package distler-shcmobile
--
-- -----------------------------------------------------------------------------
/*****************************************************************************************************/
SET NOCOUNT ON

/*****************************************************************************************************/
Declare @name varchar(500)
/*****************************************************************************************************/
 
PRINT N'/*****************************************************************************************************/'
PRINT N'Dropping Stored Procedures...'
/*****************************************************************************************************/
Declare curSp CURSOR SCROLL STATIC READ_ONLY FOR
Select
      name
From sys.objects
WHERE name LIKE N'SP[_]MOB[_]%' AND type IN (N'P', N'X')
Open curSp 
Fetch Next From curSp Into @name 
While @@fetch_status = 0 
Begin 
   RAISERROR(@name, 0, 1) WITH NOWAIT 
   Exec('drop procedure ' + @name) 
   Fetch Next From curSp Into @name 
End
Close curSp 
Deallocate curSp

PRINT N'/*****************************************************************************************************/'
PRINT N'Dropping Functions...'
/*****************************************************************************************************/
Declare curFn CURSOR SCROLL STATIC READ_ONLY FOR
Select
      name
From sys.objects
WHERE name LIKE N'FN[_]MOB[_]%' AND type IN (N'FN', N'IF', N'TF')
Open curFn
Fetch Next From curFn Into @name
While @@fetch_status = 0
Begin
   RAISERROR(@name, 0, 1) WITH NOWAIT
   Exec('drop function ' + @name)
   Fetch Next From curFn Into @name
End
Close curFn
Deallocate curFn

PRINT N'/*****************************************************************************************************/'
PRINT N'Dropping Views...'
/*****************************************************************************************************/
Declare curV CURSOR SCROLL STATIC READ_ONLY FOR
Select
      name
From sys.objects
WHERE name LIKE N'V[_]MOB[_]%' AND type IN (N'V')
Open curV 
Fetch Next From curV Into @name 
While @@fetch_status = 0 
Begin 
   RAISERROR(@name, 0, 1) WITH NOWAIT 
   Exec('drop view ' + @name) 
   Fetch Next From curV Into @name 
End
Close curV 
Deallocate curV 

PRINT N'/*****************************************************************************************************/'
PRINT N'Dropping Tables...'
/*****************************************************************************************************/
Declare curTb CURSOR SCROLL STATIC READ_ONLY FOR
Select
      name
From sys.objects
WHERE name LIKE N'MOB[_]%' AND type IN (N'U')
Open curTb 
Fetch Next From curTb Into @name 
While @@fetch_status = 0 
Begin 
   RAISERROR(@name, 0, 1) WITH NOWAIT 
   Exec('drop table ' + @name) 
   Fetch Next From curTb Into @name 
End
Close curTb 
Deallocate curTb 

/*****************************************************************************************************/
SET NOCOUNT OFF