Help me with this query with variables

Cross posting the response: Help me fix this query uzi - #3 by pyrrho