--begin tran
-- Remove system templates from Templates table and alter system userinterfaces "UserCreated" field to 1. 1 means that the userinterface record is for a system template.

Declare @Name varchar(256)

--select * from Templates where TemplateGroup = 8
--order by TemplateNumber

Declare TemplateCur Cursor Fast_Forward READ_ONLY For
	select Name from Templates WITH (NOLOCK)
	where TemplateGroup = 8 and UserCreated = 1 

Open TemplateCur

Fetch Next From TemplateCur into @Name

WHILE (@@FETCH_STATUS<>-1)
Begin
	update Templates set UserCreated = 1 
	where Name = @Name
	Fetch Next From TemplateCur into @Name
end

Close TemplateCur
Deallocate TemplateCur

delete from Templates where TemplateGroup = 8 and UserCreated = 1 and TemplateType = 1


--select * from Templates where TemplateGroup = 8
--order by TemplateNumber



--rollback tran