免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3472 | 回复: 2
打印 上一主题 下一主题

sybase触发器运行时提示subquery的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-03-17 18:11 |只看该作者 |倒序浏览
10可用积分
新建一个update触发器
   说明:
   (1)table1的表中在insert数据,insert的数据中有的数据过一段时间starttime也在update
  (2)  如果表table1中数据Severity>=3并且starttime已update,就向table2插入数据,插入字段得值为ip, hostname,field1,Severity,starttime
   当向table1表insert数据,有的数据可触发insert到table2,但有的数据insert到table1时提示下面的错误:
Subquery returned more than 1 value.  This is illegal when the subquery follows =, !=, <, <= , >, >=, or when the subquery is used as an expression.

请问如何修改?

create trigger trigger_update
on table1
for update
as

DECLARE   @newip  varchar(64)  
DECLARE   @newhostname  varchar(64)  
DECLARE   @newfield1    varchar(64)  
DECLARE   @newfield2    varchar(64)  
DECLARE   @newSeverity  NUMERIC(9,0)  
DECLARE   @newstarttime datetime
DECLARE   @newserial NUMERIC(9,0)
    if(update(starttime))
      if (select table1.Severity from table1,inserted where table1.serial=inserted.serial)>=3
BEGIN
   
   select @newip=ip, @newhostname=hostname,@newfield1=field1,@newfield2=field2,
          @newSeverity=Severity,@newstarttime=starttime,@newserial=serial
    FROM inserted
  
  INSERT INTO table2
  VALUES (@newip, @newhostname,@newfield1, @newSeverity,@newstarttime,@newserial)

END

GO

[ 本帖最后由 david0 于 2009-3-17 18:16 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2009-03-17 22:16 |只看该作者
表达式中不能使用子查询,先计算table1.Severity值,再去比较

论坛徽章:
0
3 [报告]
发表于 2009-03-18 10:23 |只看该作者
原帖由 xmltiger 于 2009-3-17 22:16 发表
表达式中不能使用子查询,先计算table1.Severity值,再去比较


能提供怎么修改吗?
    就是只要满足表table1中Severity>=3并且starttime在更新的记录就把这条记录insert到table2中。

table1的数据
insert into table1 (ip,field1,Severity,starttime,serial) values ('192.168.1.1','test1',3,'2008-03-05',11)
过一段时间后starttime '2008-03-05'可能会变成'2008-03-06'
即这条记录变成'192.168.1.1','test1',3,'2008-03-06',11,也要把这条记录当成新的记录Insert到table2中
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP