Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Specify SQL Type Expand / Collapse
Author
Message
Posted Thursday, May 1, 2014 5:00 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, July 14, 2016 3:35 PM
Points: 97, Visits: 368
Hello

I have a CLR SQL Function with a signature that looks like this...

public static long fnCreateKey(string value)
{
...
}

The function is working fine. However, in SSMS this is what the signature looks like...

[dbo].[fnCreateKey](@value [nvarchar](4000))

That function shouldn't get anything larger than varchar(9). Is there a way to change the type from a nvarchar to a varchar and change the length from 4000 to 9?

Thanks!
Post #1566877
Posted Thursday, May 1, 2014 5:24 PM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Monday, July 25, 2016 11:39 AM
Points: 506, Visits: 2,772
cgreathouse (5/1/2014)
Hello

I have a CLR SQL Function with a signature that looks like this...

public static long fnCreateKey(string value)
{
...
}

The function is working fine. However, in SSMS this is what the signature looks like...

[dbo].[fnCreateKey](@value [nvarchar](4000))

That function shouldn't get anything larger than varchar(9). Is there a way to change the type from a nvarchar to a varchar and change the length from 4000 to 9?

Thanks!


Hey there. A few things to mention:


  • Use SqlFacet to tell Visual Studio how to generate certain properties of input/output params. In this case: fnCreateKey([SqlFacet(MaxSize = 9)] SqlString value)

  • You should use the Sql types instead of native .Net types for input/output params. So use either SqlString or SqlChars instead of string.

  • No, you cannot do VARCHAR. NVARCHAR / NCHAR is the only option with SQLCLR



Take care,
Solomon...





SQL# - http://www.SQLsharp.com/
Post #1566879
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse