导航:
论坛 -> 数据库专区
斑竹:liumazi,waterstone
作者:
2004/5/9 14:32:11
标题:
加入我的收藏
楼主:
我在SQL2000中编写一存储过程: insert into table1(a1,a2,..) select (a1,a2...) from table2 在table1的触发器insert : if (select a1 from inserted)= 'a' update tabel3 set b1='addgg1' if (select a1 from inserted)= 'b' update tabel3 set b1='12358' ..... if (select a1 from inserted)= 'x' update tabel3 set b1='6b3p' 当table2中只有一条记录时,可以得到预期的结果, 当table2中多于一条记录时,table1,table3无变化,不能更新? 请教各位高手如何解决? 万分感谢!!!!
----------------------------------------------
-
作者:
2004/5/9 15:13:18
1楼:
我觉得你的(select a1 from inserted)= 'a' 有问题 还是用if exist(select * from inserted where a1='a') update tabel3 set b1='addgg1' 语句试试!
----------------------------------------------
-
作者:
2004/5/9 15:21:07
2楼:
就是1樓說的問題。 而且應該是﹕ if exists(select * from inserted where a1='a') update tabel3 set b1='addgg1'
----------------------------------------------
-
作者:
2004/5/9 16:03:30
3楼:
语句没有问题, 要不然当table2中只有一条记录就可以得到期望值
----------------------------------------------
-
作者:
2004/5/9 16:19:59
4楼:
你用我寫得代碼試試﹐我試過了﹐當table2中有多筆記錄也可以。
----------------------------------------------
-
作者:
2004/5/9 16:38:44
5楼:
楼主的做法是错误的,如果table2中有多条记录,那么a1可能出现多个重复的值,而select 语对返回的多个值就不能用"="来判断
----------------------------------------------
我真的不会!
作者:
2004/5/9 17:35:14
6楼:
我晚上试试, 试好了告诉你们!!!
----------------------------------------------
-
作者:
2004/5/9 20:18:18
7楼:
没有用,不过我改了一下存储过程Insert,问题解决了! 谢谢大家!!
----------------------------------------------
-