一个简单的SQL函数

huejim 2003-12-29 11:05:54
为什么下面的函数总提示:
在关键字 'asc' 附近有语法错误。
请问在SQL里asc函数可以用哪个函数代替?或有没有更多的函数推荐,谢谢大家

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
...全文
45 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
huejim 2003-12-29
  • 打赏
  • 举报
回复
没错就是Rotaxe(程序员) 的那种,谢谢
IDWB 2003-12-29
  • 打赏
  • 举报
回复
有没有试过
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
Rotaxe 2003-12-29
  • 打赏
  • 举报
回复
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
可以运行,不知道是不是楼主意思
huejim 2003-12-29
  • 打赏
  • 举报
回复
难道没人知道吗?up
huejim 2003-12-29
  • 打赏
  • 举报
回复
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

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧