|
我以前也碰到过类似的问题,我找到那些代码,但是只找到自己写的唯一一句注释:
--must insert one by one
我的存储过程是这样的
CREATE TRIGGER newEmp ON dbo.employee
FOR INSERT AS /*添加新员工的触发器*/
DECLARE @depID int /*depID: 部门编号*/
SET @depID= (SELECT depID FROM inserted )
SET NOCOUNT ON
IF @depID <>0 /*如果新员工已经被指定了一个部门,那么将该部门默认权限指定给他*/
INSERT INTO empRights /*empRights: 员工权限表*/
SELECT @@identity, rID, needCensor, rights, censorDepID, censorEmpID, 0
FROM depRights WHERE depRights.depID = @depID
SET NOCOUNT OFF
--must insert one by one (除了这句,所有的注释都是现在加的)
我记得我的问题来自SET @depID= (SELECT depID FROM inserted ),因为同时提交多条记录后,即使对于不同的depID,SET @depID=select...这条语句, 只给出select结果的第一个值。
我看了你写的两个存储过程后, 第一个:
update @ckcl set clh=(select 材料编号 from inserted)
同我上面这个有相似地方。
第二个,用cursor:
for select 仓库编号 from tbl仓库 select @clh=材料编号 from inserted
就不存在上述这个问题了。
我想,问题的根源在于,触发器动作后,无论你一次提交了多少条记录,你在触发器中设置的变量,不要指望它还能按照你的要求根据每条提交的记录改变。
|
|