I\'m trying to count how many words there are in a string in SQL.
Select (\"Hello To Oracle\") from dual;
I want to show the number of wor
DECLARE @List NVARCHAR(MAX) = ' ab a
x'; /*Your column/Param*/
DECLARE @Delimiter NVARCHAR(255) = ' ';/*space*/
DECLARE @WordsTable TABLE (Data VARCHAR(1000));
/*convert by XML the string to table*/
INSERT INTO @WordsTable(Data)
SELECT Data = y.i.value('(./text())[1]', 'VARCHAR(1000)')
FROM
(
SELECT x = CONVERT(XML, ''
+ REPLACE(@List, @Delimiter, '')
+ '').query('.')
) AS a CROSS APPLY x.nodes('i') AS y(i)
/*Your total words*/
select count(*) NumberOfWords
from @WordsTable
where Data is not null;
/*words list*/
select *
from @WordsTable
where Data is not null
/from this Logic you can continue alon/