免费注册 查看新帖 |

Chinaunix

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

sybase update触发器执行出错的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-03-16 16:33 |只看该作者 |倒序浏览
触发器执行时报错:
   当insert数据,提示下面的错误:
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

table1的表中在insert数据,insert的数据中有的数据过一段时间starttime也在update
现要求:
   如果表table1中数据Severity>=3并且starttime已update,就向table2插入数据,插入字段得值为ip, hostname,field1,Severity,starttime

create table table1 (
   ip  varchar(64) not null,
   hostname  varchar(64) null,
   field1    varchar(64) null,
   field2    varchar(64) null,
   Severity  NUMERIC(9,0) null,
   starttime datetime not null,
   serial NUMERIC(9,0) not null)

  serial是pk
create table table2 (
   ip  varchar(64) not null,
   hostname  varchar(64) null,
   field1    varchar(64) null,
   Severity  NUMERIC(9,0) null,
   starttime datetime not null,
   serial NUMERIC(9,0) not null)

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

论坛徽章:
0
2 [报告]
发表于 2009-03-17 13:06 |只看该作者
把你语句里的,重新改一次

论坛徽章:
0
3 [报告]
发表于 2009-03-18 10:25 |只看该作者
原帖由 camham 于 2009-3-17 13:06 发表
把你语句里的,重新改一次


能告诉一下具体怎么改吗?

         谢谢!

论坛徽章:
0
4 [报告]
发表于 2009-03-18 12:59 |只看该作者
里面有中文“,”,改成英文模式下的“,”就可以了

论坛徽章:
0
5 [报告]
发表于 2009-03-18 17:43 |只看该作者
原帖由 camham 于 2009-3-18 12:59 发表
里面有中文“,”,改成英文模式下的“,”就可以了




我在试一下。

[ 本帖最后由 david0 于 2009-3-18 17:48 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP