另外,你的触发器写法有问题:1. 不能处理多条记录的情况。“select @bh=num from updated”只能得到updated的所有记录的最后一条。2. 累赘。这样的逻辑,只要一条SQL语句就可以写好了,比你的应该简短、清楚。
你这不是SQL Server的触发器吧? CREATE TRIGGER [serupdate] ON dbo.server_t FOR UPDATE AS declare @xh int,@bh char(10),@accdate datetime,@st nchar(10)select @bh=num from updated -- 有这个表吗?(有也只能取到一条)select @accdate=max(acceptdate) from server_t where num=@bhselect @st=state from server_t where num=@bh and acceptdate=@accdateupdate equipment set state=@st where num=@bh and state!=@st(!=是什么用法,SQL中用 <>
CREATE TRIGGER [serupdate] ON dbo.server_t
FOR UPDATE
AS
declare @xh int,@bh char(10),@accdate datetime,@st nchar(10)select @bh=num from updated -- 有这个表吗?(有也只能取到一条)select @accdate=max(acceptdate) from server_t where num=@bhselect @st=state from server_t where num=@bh and acceptdate=@accdateupdate equipment set state=@st where num=@bh and state!=@st(!=是什么用法,SQL中用 <>
”这样的逻辑,只要一条SQL语句就可以写好了,比你的应该简短、清楚。“
请问怎么实现?