Although inconvenient, you can, however, dynamically check the length of a parameter before calling, for example.
CREATE FUNCTION MyFunction(@MyParameter varchar(10)) RETURNS int AS BEGIN RETURN LEN(@MyParameter) END GO DECLARE @MyValue varchar(15) = '123456789012345' DECLARE @ParameterMaxLength int SELECT @ParameterMaxLength = CHARACTER_MAXIMUM_LENGTH FROM INFORMATION_SCHEMA.PARAMETERS WHERE SPECIFIC_SCHEMA = 'dbo' AND SPECIFIC_name = 'MyFunction' AND PARAMETER_NAME = '@MyParameter' IF @ParameterMaxLength <> -1 AND LEN(@MyValue) > @ParameterMaxLength PRINT 'It' too looooooooooooooooooong'
I skipped the database name of the called function in the request and in the link to INFORMATION_SCHEMA.PARAMETERS to make sure that my sample will work unchanged.
I do not necessarily defend this, but I would like to point out that the information may be available to detect imminent truncation dynamically, if necessary in some critical situation.
Wayne erfling
source share