The FORMAT function can't be executed if it's wrapped inside the common language runtime (CLR) in Microsoft SQL Server 2012 Service Pack 3 (SP3), SQL Server 2014 SP2, or SQL Server 2016. This issue occurs when you set the PERMISSION_SET property to SAFE.
The issue was first fixed in the following cumulative updates of SQL Server:
- Cumulative Update 2 for SQL Server 2016
- Cumulative Update 1 for SQL Server 2014 SP2
- Cumulative Update 8 for SQL Server 2014 SP1
- Cumulative Update 4 for SQL Server 2012 SP3
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.