david0 发表于 2009-03-16 16:33

sybase update触发器执行出错的问题

触发器执行时报错:
   当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   @newipvarchar(64)
DECLARE   @newhostnamevarchar(64)
DECLARE   @newfield1    varchar(64)
DECLARE   @newfield2    varchar(64)
DECLARE   @newSeverityNUMERIC(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 (
   ipvarchar(64) not null,
   hostnamevarchar(64) null,
   field1    varchar(64) null,
   field2    varchar(64) null,
   SeverityNUMERIC(9,0) null,
   starttime datetime not null,
   serial NUMERIC(9,0) not null)

serial是pk
create table table2 (
   ipvarchar(64) not null,
   hostnamevarchar(64) null,
   field1    varchar(64) null,
   SeverityNUMERIC(9,0) null,
   starttime datetime not null,
   serial NUMERIC(9,0) not null)

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

camham 发表于 2009-03-17 13:06

把你语句里的,重新改一次

david0 发表于 2009-03-18 10:25

原帖由 camham 于 2009-3-17 13:06 发表 http://bbs3.chinaunix.net/images/common/back.gif
把你语句里的,重新改一次

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

         谢谢!

camham 发表于 2009-03-18 12:59

里面有中文“,”,改成英文模式下的“,”就可以了

david0 发表于 2009-03-18 17:43

原帖由 camham 于 2009-3-18 12:59 发表 http://bbs3.chinaunix.net/images/common/back.gif
里面有中文“,”,改成英文模式下的“,”就可以了



我在试一下。

[ 本帖最后由 david0 于 2009-3-18 17:48 编辑 ]
页: [1]
查看完整版本: sybase update触发器执行出错的问题