UDFRaiseError
							Raises an error from a SQL Server user defined function
						
					- Free Function
 - SQL Server Compatibility: 2008, 2012, 2014, 2016, 2017
 
SELECT SQLHTTP.net.UDFRaiseError ( @PROCID, @Message )
| Name | Type | Description | 
|---|---|---|
| @ProcID | int | A placeholder for the @@PROCID global variable. | 
| @Message | nvarchar(MAX) | Error Message to be raised. | 
bit
SQL Server user defined functions do not allow raising custom errors. This function, as shown in the example below, facilitates this functionality.
| 
					 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26  | 
						CREATE FUNCTION dbo.IsWeekday (    @Weekday tinyint ) RETURNS bit AS BEGIN     DECLARE @ReturnValue bit     IF @Weekday < 1 OR @Weekday > 7         BEGIN             DECLARE @Dummy bit             SET @Dummy = SQLHTTP.net.UDFRaiseError(@@PROCID, 'Invalid @Weekday parameter value')         END     IF @Weekday IN (1,7)         BEGIN             SET @ReturnValue = 0         END     ELSE         BEGIN             SET @ReturnValue = 1         END     RETURN @ReturnValue END GO  | 
					
| 
					 1 2 3  | 
						SELECT dbo.IsWeekday(7)  | 
					
| 
					 1 2 3 4  | 
						------------ 0  | 
					
| 
					 1 2 3  | 
						SELECT dbo.IsWeekday(8)  | 
					
Msg 6522, Level 16, State 1, Line 27
A .NET Framework error occurred during execution of user-defined routine or aggregate “udf_clr_UDFRaiseError”:
System.Exception:
				A .NET Framework error occurred during execution of user-defined routine or aggregate “udf_clr_UDFRaiseError”:
System.Exception:
**************************************
*  Invalid @Weekday parameter value  *
**************************************
System.Exception:
   at A..(String )
   at UserDefinedFunctions.udf_clr_UDFRaiseError(String Message)