Accordingly to the comments under solution#1...
You have to create a function:
Create User-defined Functions (Database Engine) - SQL Server | Microsoft Docs[
^]
USE [test]
GO
IF OBJECT_ID (N'dbo.udf_SentenceToMulti', N'TF') IS NOT NULL
DROP FUNCTION dbo.udf_SentenceToMulti;
GO
CREATE FUNCTION [dbo].[udf_SentenceToMulti](@AccountId INT, @Name VARCHAR(150))
RETURNS @tmpTable TABLE
(
SubSentenceId INT PRIMARY KEY NOT NULL,
AccountId INT NOT NULL,
NewSentence VARCHAR(MAX) NOT NULL
)
AS
BEGIN
WITH InitialTable AS
(
SELECT @AccountId AS AccountId, s.value AS Word, ROW_NUMBER() OVER(ORDER BY CHARINDEX(s.value, @Name)) AS WordId
FROM STRING_SPLIT(@Name, ' ') s
), CTE AS
(
SELECT 1 AS LoopNo, AccountId, WordID, Word, CONVERT(VARCHAR(MAX), Word) As NewSentence
FROM InitialTable
UNION ALL
SELECT LoopNo + 1 AS LoopNo, t2.AccountId, t2.WordID, t2.Word, CONCAT(NewSentence, t2.Word) AS NewSentence
FROM CTE t1 INNER JOIN InitialTable t2 ON t1.WordID +1 = t2.WordID
WHERE t1.WordID<= LoopNo +2
)
INSERT INTO @tmpTable
SELECT ROW_NUMBER() OVER(ORDER BY RowNo, LoopNo) AS SubSentenceId, AccountID, NewSentence
FROM
(
SELECT WordID, AccountId, NewSentence, LoopNo, DENSE_RANK() OVER(PARTITION BY LoopNo ORDER BY WordID) RowNo
FROM CTE
) T
ORDER BY RowNo, LoopNo
RETURN
END;
GO
Usage:
USE test;
;WITH AllSentences AS
(
SELECT ID, [Name]
FROM Account
)
SELECT a.ID, a.[Name], b.NewSentence
FROM AllSentences a
CROSS APPLY udf_SentenceToMulti(a.ID, a.[Name]) b
Example result:
1 This is a sentence This
1 This is a sentence Thisis
1 This is a sentence Thisisa
1 This is a sentence Thisisasentence
1 This is a sentence is
1 This is a sentence isa
1 This is a sentence isasentence
1 This is a sentence a
1 This is a sentence asentence
1 This is a sentence sentence
2 This is another sentence This
2 This is another sentence Thisis
2 This is another sentence Thisisanother
2 This is another sentence Thisisanothersentence
2 This is another sentence is
2 This is another sentence isanother
2 This is another sentence isanothersentence
2 This is another sentence another
2 This is another sentence anothersentence
2 This is another sentence sentence
...