if not exists(select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'CSEasyScriptSupportedPages' and COLUMN_NAME = 'PageType')
begin
	alter table [dbo].[CSEasyScriptSupportedPages]
		add [PageType] nchar(1) NOT NULL DEFAULT('')
end
go

delete from DDTests where Tablename = 'CSEasyScriptSupportedPages' and FieldName = 'PageType'
go

insert into DDTests(DatabaseChar, Tablename, FieldName, DisplayChar, Description, TermId, Options, SeqNr) values('V', 'CSEasyScriptSupportedPages', 'PageType', 'V', 'View', 855, '', 0)
insert into DDTests(DatabaseChar, Tablename, FieldName, DisplayChar, Description, TermId, Options, SeqNr) values('E', 'CSEasyScriptSupportedPages', 'PageType', 'E', 'Edit', 25319, '', 1)
insert into DDTests(DatabaseChar, Tablename, FieldName, DisplayChar, Description, TermId, Options, SeqNr) values('S', 'CSEasyScriptSupportedPages', 'PageType', 'S', 'Search', 8788, '', 2)
go

update [dbo].[CSEasyScriptSupportedPages]
set [PageType] = 'V'
where IsMaintScreen = 0
go

update [dbo].[CSEasyScriptSupportedPages]
set [PageType] = 'E'
where IsMaintScreen = 1
go

if not exists(select * from [dbo].[CSEasyScriptSupportedPages] where ASPXPage = N'CRMSearch.aspx')
begin
	insert into [dbo].[CSEasyScriptSupportedPages](ID, Caption, CaptionID, ASPXPage, DefaultColumn, IsMaintScreen, DefaultRow, TableName, KeyColumn, KeyInputField, BusinessComponent, CardID, PageType)
	values(newId(), N'Search accounts', 41545, N'CRMSearch.aspx', N'', 0, null, 'Cicmpy', 'cmp_wwn', '', 'Associates', '', 'S')
end
go
