Another possible fix for SQL function nesting