Hi @Debilon ,
Here is a more reliable method to count number of words in a column.
I removed (1) question marks and (2) commas to prevent counting them as words.
It is still not clear about your desired output. Please update your question.
SQL
-- DDL and sample data population, start
DECLARE @tbl AS TABLE (id int identity(1,1) PRIMARY KEY, string varchar(100));
INSERT INTO @tbl VALUES
('This Has 4 words.'),
('One Two Three'),
('I know what, you, have, done, last, summer ?'),
('Is this you? ');
-- DDL and sample data population, end
DECLARE @separator CHAR(1) = SPACE(1)
, @removeChars CHAR(2) = '?,';
SELECT t.*
, wordCount
, new_ID = IIF(wordCount=3, t.ID, NULL)
FROM @tbl AS t
CROSS APPLY (SELECT TRY_CAST('<root><r>' +
REPLACE(TRANSLATE(string,@removeChars,SPACE(LEN(@removeChars))), @separator, '</r><r>') +
'</r></root>' AS XML)) AS t1(c)
CROSS APPLY (SELECT c.value('count(/root/r[text()])', 'INT')) AS t2(wordCount);
Output
+----+----------------------------------------------+-----------+--------+
| id | string | wordCount | new_ID |
+----+----------------------------------------------+-----------+--------+
| 1 | This Has 4 words. | 4 | NULL |
| 2 | One Two Three | 3 | 2 |
| 3 | I know what, you, have, done, last, summer ? | 8 | NULL |
| 4 | Is this you? | 3 | 4 |
+----+----------------------------------------------+-----------+--------+