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 INTEXECUTE dbo.CLRSum 4, 3, @valueSELECT @ValueNotice 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 INTEXECUTE dbo.CLRSum 4, 3, @value outputSELECT @Value
Thank you... Thank you...Thank you...ReplyDelete
I can go home today, Friday evening knowing I have a clr proc that works ready for use in my project next week.
OMG thank you! Couldn't figure out why my output parameter was always getting set to 0.ReplyDelete
Seven years later, and your post is still helping people. Thanks :)ReplyDelete