日期:2014-05-17 浏览次数:20746 次
alter FUNCTION [dbo].[StringSplit] ( @String VARCHAR(MAX) , @Spliter VARCHAR(5) ) RETURNS @Tb TABLE ( Keyword VARCHAR(45) , Weight VARCHAR(MAX)--NUMERIC(2, 1) ) AS BEGIN DECLARE @Index INT , @One VARCHAR(45) , @Two VARCHAR(max)--NUMERIC(2, 1) SET @Index = CHARINDEX(@Spliter, @String) WHILE ( @Index > 0 ) BEGIN SET @One = LEFT(@String, @Index-1 ) SET @String = RIGHT(@String, LEN(@String) - @Index) SET @Index = CHARINDEX(@Spliter, @String) SET @Two = CAST(LEFT(@String, @Index-1 ) AS varchar(max)) INSERT INTO @TB ( Keyword, Weight ) VALUES ( @One, @Two ) SET @String = RIGHT(@String, LEN(@String) - @Index) SET @Index = CHARINDEX(@Spliter, @String) END RETURN END