Function is not working with varchar records