My t-sql split functionset ANSI_NULLS ON
My t-sql split function
set QUOTED_IDENTIFIER ON
My t-sql split function
go
My t-sql split function
My t-sql split function
My t-sql split function
My t-sql split function
ALTER FUNCTION [dbo].[JoeySplitWords](@text nvarchar(4000))
My t-sql split function
RETURNS @words TABLE (word nvarchar(4000))
My t-sql split function
AS
My t-sql split function
BEGIN
My t-sql split function    
DECLARE @wordBegin smallint,
My t-sql split function        
@wordEnd smallint,
My t-sql split function        
@word nvarchar(4000)
My t-sql split function
My t-sql split function    
SELECT @wordBegin = 1
My t-sql split function
My t-sql split function    
WHILE @wordBegin <= LEN(@text)
My t-sql split function    
BEGIN
My t-sql split function        
SELECT @wordEnd = CHARINDEX(','@text@wordBegin- 1
My t-sql split function        
IF(@wordEnd - @wordBegin < -1)-- not found
My t-sql split function
        BEGIN
My t-sql split function          
SELECT @word = LTRIM(RTRIM(SUBSTRING(@text@wordBeginLEN(@text- @wordBegin + 1)))
My t-sql split function          
INSERT INTO @words(word) VALUES(@word)
My t-sql split function          
BREAK
My t-sql split function        
END
My t-sql split function        
ELSE IF(@wordEnd - @wordBegin = -1)-- found ','
My t-sql split function
        BEGIN
My t-sql split function          
SELECT @wordBegin = @wordEnd + 2
My t-sql split function        
END
My t-sql split function        
ELSE-- found
My t-sql split function
        BEGIN
My t-sql split function          
SELECT @word = LTRIM(RTRIM(SUBSTRING(@text@wordBegin@wordEnd - @wordBegin + 1)))
My t-sql split function          
INSERT INTO @words(word) VALUES(@word)
My t-sql split function          
SELECT @wordBegin = @wordEnd + 2
My t-sql split function        
END
My t-sql split function    
END
My t-sql split function    
My t-sql split function    
RETURN
My t-sql split function
END
My t-sql split function
My t-sql split function
My t-sql split function
My t-sql split function

相关文章: