Reputation: 19697
When creating a user defined function is it "bad" to just automatically use the largest string possible?
For example, given the following UDF, I've used nvarchar(max)
for my input string, where I know perfectly well that the function currently isn't going to need to accept nvarchar(max)
and maybe I'm just forward thinking too much, but I supposed that there would always be the possibility that maybe an nvarchar(max)
would be passed to this function.
By doing something "bad" I'm wondering that by declaring that this function could possibly receive and actual nvarchar(max)
am I doing anything to possibly cripple performance?
CREATE FUNCTION [dbo].[IsMasNull] (@value nvarchar(max))
RETURNS BIT
AS
BEGIN
RETURN
CASE
WHEN @value IS NULL THEN 1
WHEN CHARINDEX(char(0), @value) > 0 THEN 1
ELSE 0
END
END
Upvotes: 2
Views: 276
Reputation: 6557
NVARCHAR(MAX) will affect performance if its a database column. As a parameter to a stored procedure it should make no difference. If at all there is a degraded performance its because of the sheer size of the data and not the datatype.
Upvotes: 1