如何迭代字符串并将字符串添加到每个位置?

non*_*ame 2 t-sql sql-server

我在TSQL中需要这样的东西

string myString = "123";
for (int i = 0;  i < myString.Length; i++)
{
   myString.Insert("ABC", i);
}
Output "ABC1ABC2ABC3"
Run Code Online (Sandbox Code Playgroud)

Ada*_*son 5

declare input as varchar(1000) -- Choose the appropriate size
declare output as varchar(1000) -- Choose the appropriate size

select @input = '123', @output = ''

declare @i int

select @i = 0

while @i < len(@input)
begin
    select @i = @i + 1

    select @output = @output + 'ABC' + substring(@input, @i, 1)
end
Run Code Online (Sandbox Code Playgroud)