By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
DECLARE @WORD AS NVARCHAR(50);
SET @WORD = 'ABCDE';
with cte as (
select 1 as n, @word as word
union all
select n + 1, word
from cte
where n < len(word)
)
select word, stuff(word, n, 1, '_')
from cte
word | (No column name) |
---|---|
ABCDE | _BCDE |
ABCDE | A_CDE |
ABCDE | AB_DE |
ABCDE | ABC_E |
ABCDE | ABCD_ |