このような更新を実行するために使用できる関数を次に示します。
数表を使用します。まだ持っていない場合は、ここで詳細を読むことができます (作成してください!)。
create function dbo.ReplaceChars(@Word varchar(max), @Char char(1))
returns varchar(max)
as
begin
declare @output varchar(1000);
set @output = replicate(@Char, len(@Word));
select @output = stuff(@output, n, 1, ' ')
from ( select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union
select 7 union select 8 union select 9 union select 10 union select 11 union select 12
) number(n) --** use your own number table here **
where substring(@Word, n, 1) = ' ' and
n <=len(@Word);
return @output;
end
--usage
declare @table table (Word varchar(max), Replacement varchar(max))
insert into @table (Word)
select 'Hello World' union all
select 'one two yak';
update @table
set Replacement = dbo.ReplaceChars(Word, '*')
where Word is not null;
select * from @table;