Split the words into character in sql server

The stored procedure is used to split the words into character.

CREATE PROCEDURE Proc_SplitWordsToChar
@Sentence VARCHAR(MAX)
AS
BEGIN
    SET NOCOUNT ON
    SET XACT_ABORT ON

DECLARE @Words VARCHAR(MAX)
DECLARE @t VARCHAR(MAX)
        DECLARE @I INT
    SET @Words = @Sentence    
    SELECT @I = 0
    WHILE(@I < LEN(@Words)+1)
    BEGIN
      SELECT @t = SUBSTRING(@words,@I,1)
 
      PRINT @t
      SET @I = @I + 1

    END
   
END

Execute this stored procedure by passing some words as input parameter.

EXEC Proc_SplitWordsToChar 'Senthilkumar publishes articles in C# corner'

The output will be like the following.

WordSplitter.jpg

Ebook Download
View all
Learn
View all