好像是有些情况会死循环,帮忙看看
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER function [dbo].[GetArticleSearchClassName](@Classid nvarchar(50))
returns varchar(100)
as
begin
declare @vStrLen int
declare @vID varchar(10)
declare @s nvarchar(100)
declare @className nvarchar(50)
declare @IntI int
--set @Operator= ' '
set @s= ' '
if (@Classid = ' ' or @Classid is null)
begin
return(@s)
end
else
begin
set @IntI = 0
while(@Classid <> ' ')
begin
IF(@IntI < 2)
BEGIN
SET @IntI = @IntI + 1
set @className= ' '
set @vStrLen=0
select @vStrLen=CHARINDEX( '| ',@Classid)--去取字符的长度
if(@vStrLen <> 0)--检索到了符号 "/ "
begin
select @vID=SUBSTRING(@Classid,1,@vStrLen-1) --取单个的ID
select @Classid=STUFF(@Classid,1,@vStrLen, ' ')--去掉前面的ID
end
else--检索没有符号 "/ "
begin
select @vID=@Classid --取单个的ID
select @Classid=STUFF(@Classid,1,len(@Classid), ' ')--去掉前面的ID
end
select @className=classname from Class where ID=@vID
if(@s <> ' ')
begin
set @s=@s+ ' => '
end
set @s=@s+@className
END
end
return(@s)
end
return(@s)
end
------解决方案--------------------Try:
ALTER function [dbo].[GetArticleSearchClassName](@Classid nvarchar(50))
returns varchar(100)
as
begin
declare @vStrLen int
declare @vID varchar(10)
declare @s nvarchar(100)
declare @className nvarchar(50)
declare @IntI int
--set @Operator= ' '
set @s=