Login  Register 
Home
 
Applications
 
Consulting
 
Design
 
Business Links
 
Support
 
Contact
  Search
Search
 
 SupportKnowledge BaseMicrosoft SQL Server     May 17, 2012  
Snippets
30

Add the helper SPLIT function to your database

CREATE FUNCTION dbo.Split
( @List nvarchar(2000), @SplitOn nvarchar(5) ) 
RETURNS @RtnValue table
( Id int identity(1, 1), Value nvarchar(100) )
AS BEGIN
   While (Charindex(@SplitOn, @List)>0) Begin
      Insert Into @RtnValue (value)
        Select Value = 
        ltrim(rtrim(Substring(@List, 1, Charindex(@SplitOn, @List)-1))) 
        Set @List = 
        Substring(@List, Charindex(@SplitOn, @List)+len(@SplitOn), len(@List))
   End
   Insert Into @RtnValue (Value)
      Select Value = ltrim(rtrim(@List))
   Return
END

Post Rating

Comments

There are currently no comments, be the first to post one.

Post Comment

Only registered users may post comments.
 

P.O. BOX 2342 ~ BREWSTER, MA 02631
PHONE & FAX: (508) 714-0678

 
 Copyright 2012 by Global Internet Business Solutions   Terms Of Use  Privacy Statement