地址
http://topic.csdn.net/u/20120103/20/55caad5e-4dcc-4a8e-ac81-8fb28e5c6ded.html
3 个解决方案
#1
现在论坛咋这么冷清啊? 难道真跟泄密那事有关啊
#2
create table info(id int identity(1,1),des varchar(30))
create table tb(A varchar(8),B varchar(8))
insert into tb
select '喜欢', '讨厌' union all
select '小孩', '大人'
create trigger tr_info on info
instead of insert
as
begin
declare @r varchar(30),@id int,@a varchar(8),@b varchar(8)
select @id=id,@r=[des] from inserted
declare ap scroll cursor for select A,B from tb
open ap
fetch first from ap into @a,@b
while(@@FETCH_STATUS<>-1)
begin
if charindex(@a,@r)>0
select @r=replace(@r,@a,@b)
fetch next from ap into @a,@b
end
close ap
deallocate ap
set identity_insert info on
insert into info(id,[des]) values(@id,@r)
set identity_insert info off
end
-- 测试插入"我喜欢小孩"
insert into info select '我喜欢小孩'
-- 结果
select * from info
id des
----------- ------------------------------
0 我讨厌大人
select * from tb
A B
-------- --------
喜欢 讨厌
小孩 大人
#3
我没有什么特别的目的, 只是想把楼主的帖子顶上去.
#1
现在论坛咋这么冷清啊? 难道真跟泄密那事有关啊
#2
create table info(id int identity(1,1),des varchar(30))
create table tb(A varchar(8),B varchar(8))
insert into tb
select '喜欢', '讨厌' union all
select '小孩', '大人'
create trigger tr_info on info
instead of insert
as
begin
declare @r varchar(30),@id int,@a varchar(8),@b varchar(8)
select @id=id,@r=[des] from inserted
declare ap scroll cursor for select A,B from tb
open ap
fetch first from ap into @a,@b
while(@@FETCH_STATUS<>-1)
begin
if charindex(@a,@r)>0
select @r=replace(@r,@a,@b)
fetch next from ap into @a,@b
end
close ap
deallocate ap
set identity_insert info on
insert into info(id,[des]) values(@id,@r)
set identity_insert info off
end
-- 测试插入"我喜欢小孩"
insert into info select '我喜欢小孩'
-- 结果
select * from info
id des
----------- ------------------------------
0 我讨厌大人
select * from tb
A B
-------- --------
喜欢 讨厌
小孩 大人
#3
我没有什么特别的目的, 只是想把楼主的帖子顶上去.