change global sql relation var to local var