I recently created a CLR stored procedure that returns a value. Not a return code but an actual calculated output. To implement this in C# it is necessary to declare an output parameter in the method definition similar to the following.
public static void CLRSum(SqlInt32 val1, SqlInt32 val2, out SqlInt32 value)
{
value = val1 + val2
}
As I alluded to in the title of this post, calls to my new CLR stored procedure where returning NULL. Below is how I was calling my CLR stored procedure from T-SQL.
DECLARE @value INT
EXECUTE dbo.CLRSum 4, 3, @value
SELECT @Value
Notice anything missing? Took me a little while but I finally realized I was missing the output keyword. The correct way to call the stored proc is below.
DECLARE @value INT
EXECUTE dbo.CLRSum 4, 3, @value output
SELECT @Value