1

我创建了从字符串中删除数字的函数

create function RemoveNumber(@inp nvarchar(50))
returns nvarchar(50)
as
begin
declare @out varchar(50)
if (@inp is NOT NULL)
begin
    set @out = ''
    while (@inp <> '')
    begin
        if (@inp like '[0-9]%')
            set @out = @out + substring(@in, 1, 1)
        set @inp = substring(@inp, 2, len(@in) - 1)
    end
end
return(@out)
end

然后我想在触发器中使用它

create trigger ut_RemoverName
on Worker
for insert
as
update Worker
set name = ut_RemoveNumber(name)

它没有看到功能。但是如何从触发器内部的 RemoveNumber 创建循环?(字段name- nvarchar(10)

4

1 回答 1

2

我猜你需要这个

create trigger ut_RemoverName on Worker
for insert
as
UPDATE w
SET Name = dbo.RemoveNumber(i.name)
FROM Worker w JOIN inserted i ON w.Id = i.Id

SQLFiddle上的演示

于 2013-01-07T08:33:32.080 回答