with clientTables as ( select substring( t.name, 1, patindex('%[_]MFR%', t.name ) - 1 ) baseTable, substring( t.name, 1, patindex('%[_]MFR%', t.name ) - 1 ) + '_MFR0' as templateTable, t.name as clientTable from sys.tables t where t.name like '#replace( url.baseTable, '_', '[_]', 'all')#%[_]MFR%' union all select substring( t.name, 1, patindex('%[_]BRO%', t.name ) - 1 ) baseTable, substring( t.name, 1, patindex('%[_]BRO%', t.name ) - 1 ) + '_MFR0' as templateTable, t.name as clientTable from sys.tables t where t.name like '#replace( url.baseTable, '_', '[_]', 'all')#%[_]BRO%' -- where t.name like 'tbl[_]DW[_]%[_]BRO%' ), toSync as ( select * from clientTables where exists ( select * from sys.tables t where t.name = templateTable ) ) select * from toSYnc where clientTable not like '%[_]MFR0' and baseTable in ( ) select * from qmd_toSync where ownerId > 0 order by ownerType, ownerId, baseTable


	
		

		
		
			
			
			
			
		
	



#_error#