-2

I have a column like this:

log
---
smart.pc
mobile.my.phone
laptop.student.school
dog.house
pc.game.headset

And I want to take only the last values after '.':

log
---
pc
phone
school
house
headset

I tried with case when log like '%.%' to take the values but in the replace after I do not know what to put in the old value's place to take all the values from the column. REPLACE(log, '', '')

Seems it has also answered here : Is there a LastIndexOf in SQL Server?

DrGenius
  • 461
  • 4
  • 14

1 Answers1

1

Perhaps the simplest way is to use string_split():

select s.value
from t cross apply
     string_split(t.log, '.') s
where t.log like '%.' + s.value;

Here is a db<>fiddle.

Gordon Linoff
  • 1,122,135
  • 50
  • 484
  • 624