Friday, September 17, 2010

Splite function

ALTER
 (
@List
 Returns
 AS

BEGIN

 
 
 BEGIN

 
 
 SET @Item = LTRIM(RTRIM(LEFT(@List,@Pos-1)))

 
 SET @List=SUBSTRING(@List,@Pos+DATALENGTH(','),8000)

 
 
RETURN
END
IF @Item<>'' INSERT INTO @Items SELECT @Item
IF @Pos=0 SET @Pos=DATALENGTH(@List)+1
SET @Pos=CHARINDEX(',',@List)
WHILE DATALENGTH(@List)>0
Declare @Pos As Int
Declare @Item As Varchar(Max)
@Items Table (Item Varchar(Max) NOT NULL)
)
As Varchar(Max)
FUNCTION [dbo].[FPSplit]

No comments:

Post a Comment