question

gotqn avatar image
gotqn asked

CLR - T-SQL and CLR types for return value do not match

I am really sorry for the lame questions but I have not got any C# experience but want to test [this][1] CLR splitter function. I have build the `rdl` and created an assembly, but I am not able to create the T-SQL function itself. This is part of the CLR function: [Microsoft.SqlServer.Server.SqlFunction( FillRowMethodName = "FillRow_Multi", TableDefinition = "item nvarchar(4000)" ) ] This is the function definition: CREATE FUNCTION [dbo].fnParseStringCLR(@string [nvarchar](MAX), @separator [nchar](255)) RETURNS TABLE ( item nvarchar (4000) ) WITH EXECUTE AS CALLER AS EXTERNAL NAME CLR_Splitter.UserDefinedFunctions.FillRow_Multi I this is the error I a getting: > Msg 6551, Level 16, State 2, Procedure > fnParseStringCLR, Line 1 CREATE > FUNCTION for "fnParseStringCLR" failed > because T-SQL and CLR types for return > value do not match. [1]: http://sqlblog.com/blogs/adam_machanic/archive/2009/04/28/sqlclr-string-splitting-part-2-even-faster-even-more-scalable.aspx
sql-server-2012clr
execution-plan.xml (190.7 KiB)
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image Kev Riley ♦♦ commented ·
Not familiar with CLR either myself, but I'm not sure that the name of your function is 'FillRow_Multi'
0 Likes 0 ·

1 Answer

·
srutzky avatar image
srutzky answered
If you copied Adam's code exactly (based on the link in the question), then the part that follows the first code block in the question is: public static IEnumerator SplitString_Multi( [SqlFacet(MaxSize = -1)] SqlChars Input, [SqlFacet(MaxSize = 255)] SqlChars Delimiter ) and hence the final line of the function definition (i.e. the second code block posted in the question) should be: EXTERNAL NAME CLR_Splitter.UserDefinedFunctions.SplitString_Multi Notice that the 3rd item of the `EXTERNAL NAME` -- SplitString_Multi -- matches the name of the method (between `IEnumerator` and `(` ).
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.