Split Strings

			
                            CREATE FUNCTION Split 
                            (
                                @Code varchar(1000),
                                @spliter char(1)
                            )
                            RETURNS @IDList table(id varchar(50))
                            AS
                            BEGIN
                            
                                DECLARE @Id Varchar(50)
                                -- Check weither the length of input string is greater then 1 or not
                                WHILE(Len(@Code) >1)
                                BEGIN
                                
                                    -- Store the First value upto spliter from the input string into a variable
                                    SELECT @Id=LEFT(@Code,CHARINDEX(@spliter, @Code)-1)
                                    -- Insert the value into a table
                                    INSERT INTO @IDList (id) VALUES (@Id)
                                    
                                    -- Find new string apart from the value seleted above
                                    SELECT @Code=SubString(@code,charIndex(@spliter,@Code)+1,Len(@Code))
                            
                                END -- End while
                            
                                RETURN -- return the table
                            END