Is it possible to create CLR stored procedure in SQL Server CLR project having input parameterof type nvarchar(max)?
If you define stored procedure:
<Microsoft.SqlServer.Server.SqlProcedure()> _
Public Shared Sub MyProcedure(ByVal param1 As String)
Then when you deploy it, param1 is of type NVarchar(4000). Is there a way to have it NVarchar(max)?
VARCHAR(MAX) or NVARCHAR(MAX) is considered as a 'large value type'. Large value types are usually stored 'out of row'. It means that the data row will have a pointer to another location where the 'large value' is stored...
The answers is: there is no different between nvarchar(7) and nvarchar(4000) in term of performance & storage size. There is an interesting thing is that: if you change nvarchar(7) or nvarchar(4000) to nvarchar(max). There is a difference in term of performance & storage size.
Solution 2. Use navarchar(max) , which has a limit of 231-1 bytes (2 GB). Avoid the old ntext type, which has been deprecated for many years, and will be removed from a future version of SQL Server. ntext, text, and image (Transact-SQL)[^]:
n defines the string size in byte-pairs and can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^30-1 characters (2 GB). The storage size is two times n bytes + 2 bytes.
You can use the SqlFacet
attribute. If you want the NVARCHAR(MAX)
type as a parameter, then you should do this:
[SqlProcedure]
public static void storedProcedure1([SqlFacet(MaxSize=-1)] String param){ .. }
If you need it as a return value in a user defined function:
[return:SqlFacet(MaxSize=-1)]
[SqlFunction]
public static String userFunction1(){ ... }
The MaxSize=-1
indicates that the size of the NVARCHAR
will be MAX
.
Define your parameter to be of type SqlChars, instead of string. See Handling Large Object Parameters in the CLR
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With