The main key is what you need to use ColumnC LIKE '% % %'so that it does not fail when the data does not contain two spaces.
If your numbers will be longer than 20-char, you can use this
SELECT ColumnA,
CASE WHEN ColumnB = 'England' AND ColumnC LIKE '% % %' THEN
RTRIM(LEFT(REPLACE(STUFF(columnc, 1, PatIndex('% %', columnc), ''), ' ', REPLICATE(' ', 20)),20))
ELSE ....
Or you can use this
SELECT ColumnA,
CASE WHEN ColumnB = 'England' AND ColumnC LIKE '% % %' THEN
SUBSTRING(
SUBSTRING(
ColumnC,
1,
CHARINDEX(' ',ColumnC,CHARINDEX(' ', ColumnC)+1)-1),
1+CHARINDEX(' ', ColumnC),
LEN(ColumnC))
ELSE ....
source
share