سؤال

I wrote a function:

CREATE FUNCTION dbo.HashConvert
(
   @value varchar(max)
   @len int
)
RETURNS varchar(max)
BEGIN
   declare @h varchar(max)

   set @h = convert(varchar(@len), hashbytes("sha1", substring(@value, 1, @len))
   /*other code*/
END

Can I use convert is this way? I need h to have a length equal to @len

set @h = SUBSTRING(CONVERT(varchar(MAX), HASHBYTES('SHA1', SUBSTRING(@value, 1, @len)),2),1,@len)

Is it ok? Or better to use varchar(22)?

هل كانت مفيدة؟

المحلول

You can't use a variable as a length specification for varchar type. Just use varchar(max) as a variable datatype and you'll be OK.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top