I need a function in sql server to insert a space in each position of an input string. For example, if the input of the function is
"example"
the output of the function should be
word1 word2
e xample
ex ample
exa mple
exam ple
examp le
exampl e
declare @S varchar(20) = 'example'
select left(@S, number) as word1,
stuff(@S, 1, number, '') as word2
from master..spt_values
where type = 'P' and
number between 1 and len(@S)-1
Or like this if you want one column with the space inserted:
select stuff(@S, number, 0, ' ') as word
from master..spt_values
where type = 'P' and
number between 2 and len(@S)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With