sqlserver insert时,字符串长度超出表字段限定的长度,报错
写一个限定字符串长度的函数
create function GetLimitStr(@str varchar(8000),@len int) returns varchar(8000) as begin if datalength(@str)<=@len return @str declare @c varchar(2) declare @pos int declare @res varchar(8000) declare @datalen int set @pos=0 set @res='' set @datalen=0 while @pos < len(@str) and @datalen < @len begin set @pos=@pos+1 set @c=substring(@str,@pos,1) set @res = @res+@c if Ascii(@c) > 127 set @datalen=@datalen+2 else set @datalen=@datalen+1 end if @datalen>@len set @res = left(@res,len(@res)-1) return @res end
标签:insert,set,res,sqlserver,len,datalen,长度 From: https://www.cnblogs.com/pandora2050/p/17578864.html