Possible fix for SQL function nesting