create function [TeststrLength] (@str varchar(3000))
returns int
as
begin
declare @l int
declare @t int
declare @c bigint
declare @i int
Set @l=len(@str)
Set @t=@l
Set @i=1
while(@i<=@l)
Begin
@c=asc(mid(@str,@i,1))    --就是这地方
If(@c<0)@c=@c+65536
If(@c>255)@t=@t+1
@i=@i+1
end
@strLength=t/2
End

解决方案 »

  1.   

    create function [TeststrLength] (@str varchar(3000))
    returns int
    as
    begin
    declare @l int
    declare @t int
    declare @c bigint
    declare @i int
    Set @l=len(@str)
    Set @t=@l
    Set @i=1
    while(@i<=@l)
    Begin
    set @c=ascii(substring(@str,@i,1))    --就是这地方
    If(@c<0)
    set @c=@c+65536
    If(@c>255)
    set @t=@t+1
    set @i=@i+1
    end
    return @t/2
    End
    可以运行,不知道是不是楼主意思
      

  2.   

    有没有试过
    create function [TeststrLength] (@str varchar(3000))
    returns int
    as
    begin
    declare @l int
    declare @t int
    declare @c bigint
    declare @i int
    Set @l=len(@str)
    Set @t=@l
    Set @i=1
    while(@i<=@l)
    Begin
    select @c=asc(mid(@str,@i,1))    --就是这地方
    If(@c<0) select @c=@c+65536
    If(@c>255) select @t=@t+1
    select @i=@i+1
    end
    select @strLength=t/2
    End
      

  3.   

    没错就是Rotaxe(程序员) 的那种,谢谢