declare @featureID uniqueidentifier, @moduleID uniqueidentifier, @entityID int
select @featureID = (select top 1 ClientModuleFeatureID from vclib.T_CLIENT_MODULE_FEATURE where name = 'AllSchetRadioButton')
	,@moduleID = (select top 1 ClientModules from vclib.T_CLIENT_MODULE_FEATURE where name = 'AllSchetRadioButton')
	,@entityID = (select top 1 EntityID from vclib.T_ENTITIES where entname = 'ACTIVE_FEATURE')

insert into vclib.T_BASE_FEATURE_SETTINGS(BaseFeatureSettingsID, ClientModuleFeature, RoleClientModules, type_)
select newid(), @featureID, t3.RoleClientModuleID, @entityID
from vclib.T_CLIENT_MODULES t1
join vclib.T_ROLE_CLIENT_MODULES t2 on (t1.ClientModuleID = t2.ClientModuleID)
join vclib.T_ROLE_CLIENT_MODULES t3 on (t2.RoleID = t3.RoleID and t3.ClientModuleID = @moduleID)
where t1.ModuleType = 'MainOfficeClientModule'
	and not exists (select * from vclib.T_BASE_FEATURE_SETTINGS bfs where bfs.RoleClientModules = t3.RoleClientModuleID and bfs.ClientModuleFeature = @featureID)
