Hi @alfygraham ,
Welcome to the microsoft TSQL Q&A forum!
Since you did not provide the expected output, I did a test with my own data:
CREATE TABLE SourcetableB(ID INT,String VARCHAR(MAX))
INSERT INTO SourcetableB VALUES(1,'abc def pqr xyz')
,(2,'pqr xyz ghi abc')
--Create user-defined functions(applies to SQL Server all supported versions)
CREATE FUNCTION SplitStr(@Sourcestr VARCHAR(8000), @Seprate VARCHAR(100))
RETURNS @result TABLE(F1 VARCHAR(100))
AS
BEGIN
DECLARE @sql AS VARCHAR(100)
SET @Sourcestr=@Sourcestr+@Seprate
WHILE(@Sourcestr<>'')
BEGIN
SET @sql=left(@Sourcestr,CHARINDEX(' ',@Sourcestr,1)-1)
INSERT @result VALUES(@sql)
SET @Sourcestr=STUFF(@Sourcestr,1,CHARINDEX(' ',@Sourcestr,1),'')
END
RETURN
END
GO
SELECT *
FROM SourcetableB s
CROSS APPLY SplitStr(S.string,' ') V;
DROP FUNCTION SplitStr
DROP TABLE SourcetableB
If you have any question, please feel free to let me know.
If the response is helpful, please click "Accept Answer" and upvote it.
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.