View Code
1 SET ANSI_NULLS ON 2 GO 3 4 SET QUOTED_IDENTIFIER ON 5 GO 6 7 CREATE FUNCTION [dbo].[Split] 8 ( 9 @c varchar(500) , 10 @split VARCHAR(500) 11 ) 12 RETURNS @t TABLE ( col VARCHAR(500) ) 13 AS 14 15 BEGIN 16 WHILE ( CHARINDEX(@split, @c) <> 0 ) 17 BEGIN 18 INSERT @t( col ) 19 VALUES ( SUBSTRING(@c, 1, CHARINDEX(@split, @c) - 1) ) 20 SET @c = STUFF(@c, 1, CHARINDEX(@split, @c), '') 21 END 22 INSERT @t( col ) VALUES ( @c ) 23 RETURN 24 END 25 26 GO