|
-- Author: happyflsytone -- Date:2008-11-05 14:59:34 -- 創(chuàng)建函數(shù) create function [dbo].[split_str] ( @s varchar(8000), --包含多個(gè)數(shù)據(jù)項(xiàng)的字符串 @index int, --要獲取的數(shù)據(jù)項(xiàng)的位置 @split varchar(10) --數(shù)據(jù)分隔符 ) returns varchar(100) as begin if @s is null return(null) begin declare @splitlen int select @splitlen=len(@split+'A')-2 end while @index>1 and charindex(@split,@s+@split)>0 begin select @index=@index-1,@s=stuff(@s,1,charindex(@split,@s+@split)+@splitlen,'') end return(isnull(left(@s,charindex(@split,@s+@split)-1),'')) end
--測(cè)試示例 select dbo.split_str('1-2-3-4',3,'-')
--運(yùn)行結(jié)果 /* 3 */ |
|
|