changed sql to use object instead of local variable