Create Table #Views(RowId Int Identity(1,1), Table_Name VarChar(300))
Insert Into #Views(Table_Name)
select distinct t.table_name
From Information_Schema.Tables t inner join sys.schemas s
on s.name=t.table_schema
where t.table_type='View' and S.name=N'TEST'
and table_name NOT like '%TESTView' and
table_name not like '%LASTView' and
table_name not like '%ABView' and
table_name not like '%CSVIEW%'
DECLARE @sViewName VARCHAR(100), @sql varchar(512)
Declare @Max Int
Declare @i int
Select @Max = Max(RowId), @i = 1
From #Views
While @i <= @Max
BEGIN
select @sviewname= table_name from #views Where RowId = @i
set @sql='drop view '+ @sviewname
exec(@sql)
set @i = @i + 1
end
Drop Table #Views