下面的函数可以判断str1中是否含有半角,返回的是半角字符的个数.怎样将他变成等效的存储过程呢?
Function halfNUM1(ByVal str1) As Integer
Dim pos As Integer
Dim strlen As Integer
Dim i As Integer
Dim str2 As String
halfNUM1 = 0
If str1 <> "" Then
strlen = Len(str1)
For i = 1 To strlen
str2 = Mid(str1, i, 1)
If Asc(str2) > 0 And str2 <> " " Then
halfNUM1 = halfNUM1 + 1
End If
Next
End If
End Function
Function halfNUM1(ByVal str1) As Integer
Dim pos As Integer
Dim strlen As Integer
Dim i As Integer
Dim str2 As String
halfNUM1 = 0
If str1 <> "" Then
strlen = Len(str1)
For i = 1 To strlen
str2 = Mid(str1, i, 1)
If Asc(str2) > 0 And str2 <> " " Then
halfNUM1 = halfNUM1 + 1
End If
Next
End If
End Function
create function f_halfNUM1(
@str1 varchar(8000)
)returns int
as
begin
declare @r int,@i int
select @r=0,@i=len(@str1)
while @i>0
select @r=@r+case
when unicode(substring(@str1,@i,1)) between 0 and 255
and substring(@str1,@i,1)<>' '
then 1 else 0 end,@i=@i-1
return(@r)
end
go--调用
select dbo.f_halfNUM1(N'中国abc')