if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_sxstr_tab]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[fn_sxstr_tab]
GO

CREATE  FUNCTION fn_sxstr_tab(@str_range varchar(255))
RETURNS @conditionrange table(rangeno varchar(20))
AS 
BEGIN 
	
	declare @para varchar(20),
			@pos int,
			@pos_old int,
			@pos1 int,
			@pos2 int,
			@start int
		
								
			set @pos = CHARINDEX('|',@str_range)
			set @pos_old = 0
						
			while @pos > 1 --分割数据符号|(1)
			begin
				if @pos_old = 0		--拆出单个
					set @para = SUBSTRING(@str_range,1 ,@pos - 1) 
				else
					set @para = SUBSTRING(@str_range,@pos_old + 1 ,@pos - @pos_old - 1) 
				if isnull(@para,'')<>''		
					INSERT into @conditionrange(rangeno) values(@para)
			
				set @pos_old = @pos
				set @start = @pos + 1
				set @pos = CHARINDEX('|',@str_range,@start)--查找下一个
			end 
			RETURN				
END 
GO