A way to make the column NameClear
contains the same content as in the column Name
, but without the accentuation, is to declare it as calculated column. Something like this:
NameClear as dbo.SemAcento (Name)
There are advantages and disadvantages to this approach.
Another option is to create trigger in the table City
where the contents of the column Name
is changed the same occurs in the column NameClear
, by applying the function that removes accentuation.
CREATE TRIGGER dbo.retira_acento_Name
on dbo.City
after INSERT, UPDATE
as
begin
declare @NI integer, @ND integer;
set @NI= (SELECT count(*) from (SELECT top (2) * from INSERTED) as I);
set @ND= (SELECT count(*) from (SELECT top (2) * from DELETED) as D);
IF @NI > 0 and @ND = 0
-- trata inclusao
begin
UPDATE C
set NameClear= dbo.SemAcento (I.Name)
from INSERTED as I
inner join dbo.City as C on C.CodeCompleto = I.CodeCompleto;
end
else
IF @NI > 0 and @ND > 0
-- trata alteração
begin
IF UPDATE (Name)
begin
UPDATE C
set NameClear= dbo.SemAcento (I.Name)
from INSERTED as I
inner join DELETED as D on D.CodeCompleto = I.CodeCompleto
inner join dbo.City as C on C.CodeCompleto = D.CodeCompleto
where I.Name <> D.Name;
end;
end;
end;
go
I have not tested; I hope you have no mistake(s).
Regarding withdraw accentuation, I suggest reading the article "Remove accent and "invisible characters"that contains interesting solutions on the subject.
Have you tried
UPDATE City SET NameClear = function(Name)
?– anonimo