Given the below string
Declare @string varchar(max)='abc ___________ deffns ___ cg _ hif _______hh ihs';
this is the Output required : (Every hypen irrespective of length should be replaced with lastname)
abc lastname deffns lastname cg lastname hif lastname hh ihs
The issue here is, there can be many Hypens
of variable length(max length can be <20)...
I tried with many methods and settled with below approach..
select
REPLACE(REPLACE(replace(stringcol,replicate('_',20),'LASTNAME'),
replicate('_',19),'LASTNAME'),
replicate('_',18),'LASTNAME')
from table
Is there a way to do accomplish this efficiently..any advice would be most welcome