/*
We need to score profiles, in order to favor the best ones
for breeding.
A profile's score is the percentage of right answers - the percentage 
of wrong answers.
A right answer matches the target column value, a wrong answer
doesn't
*/
create function uf_profile_Score (@target_value varchar(255))
returns table
as
return
(	   select r.id as id, 
           r.number_selected as number_right, 
           w.number_selected as number_wrong,
           (r.number_selected/1.0/r.number_actual/1.0) -
           (w.number_selected/1.0/w.number_actual/1.0) as score 

		from t_profile_results r, t_profile_results w
		where     r.target_value = @target_value and
		       w.target_value != @target_value and
		       r.id = w.id
)
go
