SELECT p.id as id, m.target as target_value,count(*) as number_selected FROM .dbo.uf_generated_profile_table() p LEFT OUTER JOIN t_mine_relations m ON (p.column1 is null or (left(p.column1,2) = '==' and substring(p.column1,4,len(p.column1)-3) = m.column1) or (left(p.column1,2) = '!=' and substring(p.column1,4,len(p.column1)-3) != m.column1) ) and ... { similar clauses for all t_mine_relations columns ... columnN} GROUP BY id, m.target
Example 2: Generation evaluator in implemented in standard SQL.