declare @sql nvarchar(max)
select @sql = 'INSERT INTO [FIES].[T_TP_TYPE_DEPENDENCY_SETTING] ([TpTypeDependencySettingID] ,[TpType] ,[SectionDependSettings]) SELECT NEWID(), tt.TpTypeID, sds.SectionDependSettingsID FROM FIES.T_TP_TYPE tt join FIES.T_SECTION_DEPEND_SETTINGS sds on ' +
  (select dbo.Joint('(sds.[' + p.SectionAlias + '] = tt.[' + p.SectionAlias + '] or sds.[' + p.SectionAlias + '] is null and tt.[' + p.SectionAlias + '] is null)', ' and ')
   from FIES.T_PLAN_SECTION p
   where p.SectionDependType = 0) + ' group by tt.TpTypeID, sds.SectionDependSettingsID'
exec sp_executesql @sql
