Using T-SQL functions in the query