id x y s
(主键) (金额1) (金额2) (状态值: 状态1)
B表字段
id x y s
(主键) (金额1) (金额2) (状态值: 状态2或状态3)
C表
id changedate changetype changecount
(主键) (改变日期) (变化类型,如是 x 或 y) (变化值)
A与B这两个表的字段结构完全一样. A表的值不会发生变化.
如果 B表中的x 或 y发生改变,则将与A表中相对应的x 或 y比较,如果值不等于0,则C表新增一条记录,把刚才比较得来的变化值写入C表的 changecount字段中.
B表(状态2)第一次与A表比较,然后更新B表的状态值为(状态3),B表(状态3)第二次只是与自己作比较,差异写入C表.
怎样写这个触发器呀?
17 个解决方案
#1
邹老大有没有空呀?
高手请帮帮忙.
高手请帮帮忙.
#2
再顶喽.
人气不旺了,还是题目有点难度?
人气不旺了,还是题目有点难度?
#3
“变化值写入C表的changecount字段中.”,这个变化值怎么存储,“a变为b”,这么存储吗,还是说只存入改变后的值??
#4
每人答我答了
#5
回复 paoluo(一天到晚游泳的鱼)
变化值 = B.x - A.x
C表中要这样写
id,getDate(),x,(B.x - A.x)
不知道我这样说你能不能看明白.我很急的,没搞出来.
#6
还有一个问题,就是x和y同时被改变了,怎么插入数据??
最好能就你的问题,列几条数据,以及你要的结果。
最好能就你的问题,列几条数据,以及你要的结果。
#7
回复: paoluo(一天到晚游泳的鱼)
如果x和y同时被改变了,则C表插入两条数据
id,getDate(),x,(B.x - A.x)
id,getDate(),y,(B.y - A.y)
如果x和y同时被改变了,则C表插入两条数据
id,getDate(),x,(B.x - A.x)
id,getDate(),y,(B.y - A.y)
#8
id,getDate(),x,(B.x - A.x)
id,getDate(),y,(B.y - A.y)
这里的ID应该是得到B表中被改变字段的ID吧。
那么这样的话,id在C表中就有重复了,不应该为主键吧。
id,getDate(),y,(B.y - A.y)
这里的ID应该是得到B表中被改变字段的ID吧。
那么这样的话,id在C表中就有重复了,不应该为主键吧。
#9
paoluo(一天到晚游泳的鱼):
接上,我的C表以id,changedate,changetype 三个字段联合作为主键,不用担心重复的.
现在关键是如何才能保证B表第一次是与A表相比较,而第二次则是B当前值与原来的值相比较.
我是通过B与A第一次比较后更新B的状态字,但是这样好象又自己触发了自己,陷入一个循环之中.
我未做完的触发器代码如下(其中有语法错误,也未能解决):
CREATE TRIGGER [tr-ProductCostCountForm-UPDATE] ON dbo.ProductCostCountForm
FOR UPDATE AS
declare @@return int
declare @@userCount int
declare @@changecount1 int
set @@changecount1 = 0
begin
if(inserted.Status = '实计就绪')
begin
select @@userCount = count(*) from EstimateCostCountForm, inserted
where (EstimateCostCountForm.ISBN=inserted.ISBN and EstimateCostCountForm.EditionOrder=inserted.EditionOrder and EstimateCostCountForm.PrintOrder = inserted.PrintOrder and EstimateCostCountForm.Status ='应计归集')
if @@userCount > 0
begin
--作者稿费
set @@changecount1 = inserted.ManuscriptFee - EstimateCostCountForm.ManuscriptFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'作者稿费',getdate(),@@changecount1,'' from inserted
end
--租型费用
set @@changecount1 = inserted.RentTypesetFee - EstimateCostCountForm.RentTypesetFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'租型费',getdate(),@@changecount1,'' from inserted
end
--材料费
set @@changecount1 = inserted.MaterialFee - EstimateCostCountForm.MaterialFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'材料费',getdate(),@@changecount1,'' from inserted
end
--印刷制作费
set @@changecount1 = inserted.TypesetFee - EstimateCostCountForm.TypesetFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'印刷制作费',getdate(),@@changecount1,'' from inserted
end
--装订费
set @@changecount1 = inserted.PrintBindFee - EstimateCostCountForm.PrintBindFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'装订费',getdate(),@@changecount1,'' from inserted
end
--出版损失
set @@changecount1 = inserted.PubLossFee - EstimateCostCountForm.PubLossFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'出版损失',getdate(),@@changecount1,'' from inserted
end
--编录经费
set @@changecount1 = inserted.EditorFee - EstimateCostCountForm.EditorFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'编录经费',getdate(),@@changecount1,'' from inserted
end
--其他直接费用
set @@changecount1 = inserted.OtherFee - EstimateCostCountForm.OtherFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'其他直接费用',getdate(),@@changecount1,'' from inserted
end
update ProductCostCountForm set ProductCostCountForm.Status = '实计归集'
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
end
return
end
else if(inserted.Status = '实计归集')
begin
return
end
end
接上,我的C表以id,changedate,changetype 三个字段联合作为主键,不用担心重复的.
现在关键是如何才能保证B表第一次是与A表相比较,而第二次则是B当前值与原来的值相比较.
我是通过B与A第一次比较后更新B的状态字,但是这样好象又自己触发了自己,陷入一个循环之中.
我未做完的触发器代码如下(其中有语法错误,也未能解决):
CREATE TRIGGER [tr-ProductCostCountForm-UPDATE] ON dbo.ProductCostCountForm
FOR UPDATE AS
declare @@return int
declare @@userCount int
declare @@changecount1 int
set @@changecount1 = 0
begin
if(inserted.Status = '实计就绪')
begin
select @@userCount = count(*) from EstimateCostCountForm, inserted
where (EstimateCostCountForm.ISBN=inserted.ISBN and EstimateCostCountForm.EditionOrder=inserted.EditionOrder and EstimateCostCountForm.PrintOrder = inserted.PrintOrder and EstimateCostCountForm.Status ='应计归集')
if @@userCount > 0
begin
--作者稿费
set @@changecount1 = inserted.ManuscriptFee - EstimateCostCountForm.ManuscriptFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'作者稿费',getdate(),@@changecount1,'' from inserted
end
--租型费用
set @@changecount1 = inserted.RentTypesetFee - EstimateCostCountForm.RentTypesetFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'租型费',getdate(),@@changecount1,'' from inserted
end
--材料费
set @@changecount1 = inserted.MaterialFee - EstimateCostCountForm.MaterialFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'材料费',getdate(),@@changecount1,'' from inserted
end
--印刷制作费
set @@changecount1 = inserted.TypesetFee - EstimateCostCountForm.TypesetFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'印刷制作费',getdate(),@@changecount1,'' from inserted
end
--装订费
set @@changecount1 = inserted.PrintBindFee - EstimateCostCountForm.PrintBindFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'装订费',getdate(),@@changecount1,'' from inserted
end
--出版损失
set @@changecount1 = inserted.PubLossFee - EstimateCostCountForm.PubLossFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'出版损失',getdate(),@@changecount1,'' from inserted
end
--编录经费
set @@changecount1 = inserted.EditorFee - EstimateCostCountForm.EditorFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'编录经费',getdate(),@@changecount1,'' from inserted
end
--其他直接费用
set @@changecount1 = inserted.OtherFee - EstimateCostCountForm.OtherFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'其他直接费用',getdate(),@@changecount1,'' from inserted
end
update ProductCostCountForm set ProductCostCountForm.Status = '实计归集'
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
end
return
end
else if(inserted.Status = '实计归集')
begin
return
end
end
#10
paoluo(一天到晚游泳的鱼):
接上,
else if(inserted.Status = '实计归集')
begin
return
end
这一点不会做,呵呵.
接上,
else if(inserted.Status = '实计归集')
begin
return
end
这一点不会做,呵呵.
#11
--建立测试环境
Create table A(
id Int Identity(1,1),
x Int,
y Int,
s Char(1))
Create table B(
id Int Identity(1,1),
x Int,
y Int,
s Char(1))
Create table C(
id Int,
changedate DateTime,
changetype Varchar(10),
changecount Varchar(50))
GO
--插入数据
Insert A Values(100,100,1)
Insert B Values(100,100,2)
GO
--建立触发器
Create Trigger [Update_C]On B
FOR UPDATE
AS
Begin
If Update(x)
Begin
Insert C Select A.id,GetDate(),'x',Rtrim(D.x)+' - '+Rtrim(A.x) from A Inner Join Inserted D On A.id=D.id And A.x<>D.x And D.s=2
Insert C Select E.id,GetDate(),'x',Rtrim(D.x)+' - '+Rtrim(E.x) from Deleted E Inner Join Inserted D On E.id=D.id And E.x<>D.x And D.s=3
Update B Set s=3 from B Inner Join Inserted D On B.id=D.id And B.s=2
End
If Update(y)
Begin
Insert C Select A.id,GetDate(),'y',Rtrim(D.y)+' - '+Rtrim(A.y) from A Inner Join Inserted D On A.id=D.id And A.y<>D.y And D.s=2
Insert C Select E.id,GetDate(),'y',Rtrim(D.y)+' - '+Rtrim(E.y)from Deleted E Inner Join Inserted D On E.id=D.id And E.y<>D.y And D.s=3
Update B Set s=3 from B Inner Join Inserted D On B.id=D.id And B.s=2
End
End
GO
--测试
Update B Set x=150,y=150 Where id=1
Select * from B
Select * from C
Update B Set x=100,y=100 Where id=1
Select * from B
Select * from C
--删除测试环境
Drop table A,B,C
--结果
/*
--第一次Update
id x y s
1 150 150 3
id changedate changetype changecount
1 2005-05-09 18:00:11.907 x 150 - 100
1 2005-05-09 18:00:11.917 y 150 - 100
--第二次Update
id x y s
1 100 100 3
id changedate changetype changecount
1 2005-05-09 18:00:11.907 x 150 - 100
1 2005-05-09 18:00:11.917 y 150 - 100
1 2005-05-09 18:00:11.917 x 100 - 150
1 2005-05-09 18:00:11.917 y 100 - 150
*/
Create table A(
id Int Identity(1,1),
x Int,
y Int,
s Char(1))
Create table B(
id Int Identity(1,1),
x Int,
y Int,
s Char(1))
Create table C(
id Int,
changedate DateTime,
changetype Varchar(10),
changecount Varchar(50))
GO
--插入数据
Insert A Values(100,100,1)
Insert B Values(100,100,2)
GO
--建立触发器
Create Trigger [Update_C]On B
FOR UPDATE
AS
Begin
If Update(x)
Begin
Insert C Select A.id,GetDate(),'x',Rtrim(D.x)+' - '+Rtrim(A.x) from A Inner Join Inserted D On A.id=D.id And A.x<>D.x And D.s=2
Insert C Select E.id,GetDate(),'x',Rtrim(D.x)+' - '+Rtrim(E.x) from Deleted E Inner Join Inserted D On E.id=D.id And E.x<>D.x And D.s=3
Update B Set s=3 from B Inner Join Inserted D On B.id=D.id And B.s=2
End
If Update(y)
Begin
Insert C Select A.id,GetDate(),'y',Rtrim(D.y)+' - '+Rtrim(A.y) from A Inner Join Inserted D On A.id=D.id And A.y<>D.y And D.s=2
Insert C Select E.id,GetDate(),'y',Rtrim(D.y)+' - '+Rtrim(E.y)from Deleted E Inner Join Inserted D On E.id=D.id And E.y<>D.y And D.s=3
Update B Set s=3 from B Inner Join Inserted D On B.id=D.id And B.s=2
End
End
GO
--测试
Update B Set x=150,y=150 Where id=1
Select * from B
Select * from C
Update B Set x=100,y=100 Where id=1
Select * from B
Select * from C
--删除测试环境
Drop table A,B,C
--结果
/*
--第一次Update
id x y s
1 150 150 3
id changedate changetype changecount
1 2005-05-09 18:00:11.907 x 150 - 100
1 2005-05-09 18:00:11.917 y 150 - 100
--第二次Update
id x y s
1 100 100 3
id changedate changetype changecount
1 2005-05-09 18:00:11.907 x 150 - 100
1 2005-05-09 18:00:11.917 y 150 - 100
1 2005-05-09 18:00:11.917 x 100 - 150
1 2005-05-09 18:00:11.917 y 100 - 150
*/
#12
paoluo(一天到晚游泳的鱼)
谢谢你的关注!!
我试了你的代码,没有问题.只是当我需要只更新B.s状态值后就要自动计算差异并写入C表的时候,那一段代码还有漏洞.
怎样实现如下功能的代码呢?
Create Trigger [Update_C]On B
FOR UPDATE
AS
Begin
if(Inserted.s=2)
Begin
If Update(x)
Begin
Insert C Select A.id,GetDate(),'x',Rtrim(D.x)+' - '+Rtrim(A.x) from A Inner Join Inserted D On A.id=D.id And A.x<>D.x And D.s=2
Update B Set s=3 from B Inner Join Inserted D On B.id=D.id And B.s=2
End
End
else if(Inserted.s=3)
Begin
If Update(x)
Insert C Select E.id,GetDate(),'x',Rtrim(D.x)+' - '+Rtrim(E.x) from Deleted E Inner Join Inserted D On E.id=D.id And E.x<>D.x And D.s=3
End
End
GO
谢谢你的关注!!
我试了你的代码,没有问题.只是当我需要只更新B.s状态值后就要自动计算差异并写入C表的时候,那一段代码还有漏洞.
怎样实现如下功能的代码呢?
Create Trigger [Update_C]On B
FOR UPDATE
AS
Begin
if(Inserted.s=2)
Begin
If Update(x)
Begin
Insert C Select A.id,GetDate(),'x',Rtrim(D.x)+' - '+Rtrim(A.x) from A Inner Join Inserted D On A.id=D.id And A.x<>D.x And D.s=2
Update B Set s=3 from B Inner Join Inserted D On B.id=D.id And B.s=2
End
End
else if(Inserted.s=3)
Begin
If Update(x)
Insert C Select E.id,GetDate(),'x',Rtrim(D.x)+' - '+Rtrim(E.x) from Deleted E Inner Join Inserted D On E.id=D.id And E.x<>D.x And D.s=3
End
End
GO
#13
再顶一把!!
#14
"只更新B.s状态值后就要自动计算差异并写入C表",更改B的状态也要写入c表吗??
#15
谢谢 paoluo(一天到晚游泳的鱼)
是"在只更新B表的状态后也相应要分别计算对应x与y 的差异,如果有差异,则写入C表"
是"在只更新B表的状态后也相应要分别计算对应x与y 的差异,如果有差异,则写入C表"
#16
"在只更新B表的状态后也相应要分别计算对应x与y 的差异,如果有差异,则写入C表"
也就是说更改了x或y,才写入c表啊。
我写的例子中,如果x或y更改了,就会写入c表,没有问题啊。
难道说改了状态,状态的改变也要写入c表,还是指别的什么??
也就是说更改了x或y,才写入c表啊。
我写的例子中,如果x或y更改了,就会写入c表,没有问题啊。
难道说改了状态,状态的改变也要写入c表,还是指别的什么??
#17
paoluo(一天到晚游泳的鱼)
不好意思,两天都未得到时间来网上了.我确实是这样想的.如果使用这个触发器时,用户只简单更新了后面的一个状态值,我也希望它能把X与Y的值比对一下.
因为如果我没有做第一次比较,而是简单更新了状态,那么下一次再进行比较就会出现错误的结果.
不过问题总算解决了,我不用触发器方式,而是在更新B表的存储过程中比较,这样也较好控制.
谢谢你.paoluo(一天到晚游泳的鱼),谢谢你这么耐心的指教!
下面结贴.
不好意思,两天都未得到时间来网上了.我确实是这样想的.如果使用这个触发器时,用户只简单更新了后面的一个状态值,我也希望它能把X与Y的值比对一下.
因为如果我没有做第一次比较,而是简单更新了状态,那么下一次再进行比较就会出现错误的结果.
不过问题总算解决了,我不用触发器方式,而是在更新B表的存储过程中比较,这样也较好控制.
谢谢你.paoluo(一天到晚游泳的鱼),谢谢你这么耐心的指教!
下面结贴.
#1
邹老大有没有空呀?
高手请帮帮忙.
高手请帮帮忙.
#2
再顶喽.
人气不旺了,还是题目有点难度?
人气不旺了,还是题目有点难度?
#3
“变化值写入C表的changecount字段中.”,这个变化值怎么存储,“a变为b”,这么存储吗,还是说只存入改变后的值??
#4
每人答我答了
#5
回复 paoluo(一天到晚游泳的鱼)
变化值 = B.x - A.x
C表中要这样写
id,getDate(),x,(B.x - A.x)
不知道我这样说你能不能看明白.我很急的,没搞出来.
#6
还有一个问题,就是x和y同时被改变了,怎么插入数据??
最好能就你的问题,列几条数据,以及你要的结果。
最好能就你的问题,列几条数据,以及你要的结果。
#7
回复: paoluo(一天到晚游泳的鱼)
如果x和y同时被改变了,则C表插入两条数据
id,getDate(),x,(B.x - A.x)
id,getDate(),y,(B.y - A.y)
如果x和y同时被改变了,则C表插入两条数据
id,getDate(),x,(B.x - A.x)
id,getDate(),y,(B.y - A.y)
#8
id,getDate(),x,(B.x - A.x)
id,getDate(),y,(B.y - A.y)
这里的ID应该是得到B表中被改变字段的ID吧。
那么这样的话,id在C表中就有重复了,不应该为主键吧。
id,getDate(),y,(B.y - A.y)
这里的ID应该是得到B表中被改变字段的ID吧。
那么这样的话,id在C表中就有重复了,不应该为主键吧。
#9
paoluo(一天到晚游泳的鱼):
接上,我的C表以id,changedate,changetype 三个字段联合作为主键,不用担心重复的.
现在关键是如何才能保证B表第一次是与A表相比较,而第二次则是B当前值与原来的值相比较.
我是通过B与A第一次比较后更新B的状态字,但是这样好象又自己触发了自己,陷入一个循环之中.
我未做完的触发器代码如下(其中有语法错误,也未能解决):
CREATE TRIGGER [tr-ProductCostCountForm-UPDATE] ON dbo.ProductCostCountForm
FOR UPDATE AS
declare @@return int
declare @@userCount int
declare @@changecount1 int
set @@changecount1 = 0
begin
if(inserted.Status = '实计就绪')
begin
select @@userCount = count(*) from EstimateCostCountForm, inserted
where (EstimateCostCountForm.ISBN=inserted.ISBN and EstimateCostCountForm.EditionOrder=inserted.EditionOrder and EstimateCostCountForm.PrintOrder = inserted.PrintOrder and EstimateCostCountForm.Status ='应计归集')
if @@userCount > 0
begin
--作者稿费
set @@changecount1 = inserted.ManuscriptFee - EstimateCostCountForm.ManuscriptFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'作者稿费',getdate(),@@changecount1,'' from inserted
end
--租型费用
set @@changecount1 = inserted.RentTypesetFee - EstimateCostCountForm.RentTypesetFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'租型费',getdate(),@@changecount1,'' from inserted
end
--材料费
set @@changecount1 = inserted.MaterialFee - EstimateCostCountForm.MaterialFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'材料费',getdate(),@@changecount1,'' from inserted
end
--印刷制作费
set @@changecount1 = inserted.TypesetFee - EstimateCostCountForm.TypesetFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'印刷制作费',getdate(),@@changecount1,'' from inserted
end
--装订费
set @@changecount1 = inserted.PrintBindFee - EstimateCostCountForm.PrintBindFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'装订费',getdate(),@@changecount1,'' from inserted
end
--出版损失
set @@changecount1 = inserted.PubLossFee - EstimateCostCountForm.PubLossFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'出版损失',getdate(),@@changecount1,'' from inserted
end
--编录经费
set @@changecount1 = inserted.EditorFee - EstimateCostCountForm.EditorFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'编录经费',getdate(),@@changecount1,'' from inserted
end
--其他直接费用
set @@changecount1 = inserted.OtherFee - EstimateCostCountForm.OtherFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'其他直接费用',getdate(),@@changecount1,'' from inserted
end
update ProductCostCountForm set ProductCostCountForm.Status = '实计归集'
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
end
return
end
else if(inserted.Status = '实计归集')
begin
return
end
end
接上,我的C表以id,changedate,changetype 三个字段联合作为主键,不用担心重复的.
现在关键是如何才能保证B表第一次是与A表相比较,而第二次则是B当前值与原来的值相比较.
我是通过B与A第一次比较后更新B的状态字,但是这样好象又自己触发了自己,陷入一个循环之中.
我未做完的触发器代码如下(其中有语法错误,也未能解决):
CREATE TRIGGER [tr-ProductCostCountForm-UPDATE] ON dbo.ProductCostCountForm
FOR UPDATE AS
declare @@return int
declare @@userCount int
declare @@changecount1 int
set @@changecount1 = 0
begin
if(inserted.Status = '实计就绪')
begin
select @@userCount = count(*) from EstimateCostCountForm, inserted
where (EstimateCostCountForm.ISBN=inserted.ISBN and EstimateCostCountForm.EditionOrder=inserted.EditionOrder and EstimateCostCountForm.PrintOrder = inserted.PrintOrder and EstimateCostCountForm.Status ='应计归集')
if @@userCount > 0
begin
--作者稿费
set @@changecount1 = inserted.ManuscriptFee - EstimateCostCountForm.ManuscriptFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'作者稿费',getdate(),@@changecount1,'' from inserted
end
--租型费用
set @@changecount1 = inserted.RentTypesetFee - EstimateCostCountForm.RentTypesetFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'租型费',getdate(),@@changecount1,'' from inserted
end
--材料费
set @@changecount1 = inserted.MaterialFee - EstimateCostCountForm.MaterialFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'材料费',getdate(),@@changecount1,'' from inserted
end
--印刷制作费
set @@changecount1 = inserted.TypesetFee - EstimateCostCountForm.TypesetFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'印刷制作费',getdate(),@@changecount1,'' from inserted
end
--装订费
set @@changecount1 = inserted.PrintBindFee - EstimateCostCountForm.PrintBindFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'装订费',getdate(),@@changecount1,'' from inserted
end
--出版损失
set @@changecount1 = inserted.PubLossFee - EstimateCostCountForm.PubLossFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'出版损失',getdate(),@@changecount1,'' from inserted
end
--编录经费
set @@changecount1 = inserted.EditorFee - EstimateCostCountForm.EditorFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'编录经费',getdate(),@@changecount1,'' from inserted
end
--其他直接费用
set @@changecount1 = inserted.OtherFee - EstimateCostCountForm.OtherFee
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
if(@@changecount1 != '0')
begin
INSERT ProductCostChangeHistory(ChoiceThemeNo,ISBN,EditionOrder,PrintOrder,FeeType,ChangeDate,ProductCostChangeMoney,ChangeReason)
SELECT inserted.ChoiceThemeNo,inserted.ISBN,inserted.EditionOrder,inserted.PrintOrder,'其他直接费用',getdate(),@@changecount1,'' from inserted
end
update ProductCostCountForm set ProductCostCountForm.Status = '实计归集'
from inserted a where (EstimateCostCountForm.ISBN=a.ISBN and EstimateCostCountForm.EditionOrder=a.EditionOrder and EstimateCostCountForm.EditionOrder=a.EditionOrder)
end
return
end
else if(inserted.Status = '实计归集')
begin
return
end
end
#10
paoluo(一天到晚游泳的鱼):
接上,
else if(inserted.Status = '实计归集')
begin
return
end
这一点不会做,呵呵.
接上,
else if(inserted.Status = '实计归集')
begin
return
end
这一点不会做,呵呵.
#11
--建立测试环境
Create table A(
id Int Identity(1,1),
x Int,
y Int,
s Char(1))
Create table B(
id Int Identity(1,1),
x Int,
y Int,
s Char(1))
Create table C(
id Int,
changedate DateTime,
changetype Varchar(10),
changecount Varchar(50))
GO
--插入数据
Insert A Values(100,100,1)
Insert B Values(100,100,2)
GO
--建立触发器
Create Trigger [Update_C]On B
FOR UPDATE
AS
Begin
If Update(x)
Begin
Insert C Select A.id,GetDate(),'x',Rtrim(D.x)+' - '+Rtrim(A.x) from A Inner Join Inserted D On A.id=D.id And A.x<>D.x And D.s=2
Insert C Select E.id,GetDate(),'x',Rtrim(D.x)+' - '+Rtrim(E.x) from Deleted E Inner Join Inserted D On E.id=D.id And E.x<>D.x And D.s=3
Update B Set s=3 from B Inner Join Inserted D On B.id=D.id And B.s=2
End
If Update(y)
Begin
Insert C Select A.id,GetDate(),'y',Rtrim(D.y)+' - '+Rtrim(A.y) from A Inner Join Inserted D On A.id=D.id And A.y<>D.y And D.s=2
Insert C Select E.id,GetDate(),'y',Rtrim(D.y)+' - '+Rtrim(E.y)from Deleted E Inner Join Inserted D On E.id=D.id And E.y<>D.y And D.s=3
Update B Set s=3 from B Inner Join Inserted D On B.id=D.id And B.s=2
End
End
GO
--测试
Update B Set x=150,y=150 Where id=1
Select * from B
Select * from C
Update B Set x=100,y=100 Where id=1
Select * from B
Select * from C
--删除测试环境
Drop table A,B,C
--结果
/*
--第一次Update
id x y s
1 150 150 3
id changedate changetype changecount
1 2005-05-09 18:00:11.907 x 150 - 100
1 2005-05-09 18:00:11.917 y 150 - 100
--第二次Update
id x y s
1 100 100 3
id changedate changetype changecount
1 2005-05-09 18:00:11.907 x 150 - 100
1 2005-05-09 18:00:11.917 y 150 - 100
1 2005-05-09 18:00:11.917 x 100 - 150
1 2005-05-09 18:00:11.917 y 100 - 150
*/
Create table A(
id Int Identity(1,1),
x Int,
y Int,
s Char(1))
Create table B(
id Int Identity(1,1),
x Int,
y Int,
s Char(1))
Create table C(
id Int,
changedate DateTime,
changetype Varchar(10),
changecount Varchar(50))
GO
--插入数据
Insert A Values(100,100,1)
Insert B Values(100,100,2)
GO
--建立触发器
Create Trigger [Update_C]On B
FOR UPDATE
AS
Begin
If Update(x)
Begin
Insert C Select A.id,GetDate(),'x',Rtrim(D.x)+' - '+Rtrim(A.x) from A Inner Join Inserted D On A.id=D.id And A.x<>D.x And D.s=2
Insert C Select E.id,GetDate(),'x',Rtrim(D.x)+' - '+Rtrim(E.x) from Deleted E Inner Join Inserted D On E.id=D.id And E.x<>D.x And D.s=3
Update B Set s=3 from B Inner Join Inserted D On B.id=D.id And B.s=2
End
If Update(y)
Begin
Insert C Select A.id,GetDate(),'y',Rtrim(D.y)+' - '+Rtrim(A.y) from A Inner Join Inserted D On A.id=D.id And A.y<>D.y And D.s=2
Insert C Select E.id,GetDate(),'y',Rtrim(D.y)+' - '+Rtrim(E.y)from Deleted E Inner Join Inserted D On E.id=D.id And E.y<>D.y And D.s=3
Update B Set s=3 from B Inner Join Inserted D On B.id=D.id And B.s=2
End
End
GO
--测试
Update B Set x=150,y=150 Where id=1
Select * from B
Select * from C
Update B Set x=100,y=100 Where id=1
Select * from B
Select * from C
--删除测试环境
Drop table A,B,C
--结果
/*
--第一次Update
id x y s
1 150 150 3
id changedate changetype changecount
1 2005-05-09 18:00:11.907 x 150 - 100
1 2005-05-09 18:00:11.917 y 150 - 100
--第二次Update
id x y s
1 100 100 3
id changedate changetype changecount
1 2005-05-09 18:00:11.907 x 150 - 100
1 2005-05-09 18:00:11.917 y 150 - 100
1 2005-05-09 18:00:11.917 x 100 - 150
1 2005-05-09 18:00:11.917 y 100 - 150
*/
#12
paoluo(一天到晚游泳的鱼)
谢谢你的关注!!
我试了你的代码,没有问题.只是当我需要只更新B.s状态值后就要自动计算差异并写入C表的时候,那一段代码还有漏洞.
怎样实现如下功能的代码呢?
Create Trigger [Update_C]On B
FOR UPDATE
AS
Begin
if(Inserted.s=2)
Begin
If Update(x)
Begin
Insert C Select A.id,GetDate(),'x',Rtrim(D.x)+' - '+Rtrim(A.x) from A Inner Join Inserted D On A.id=D.id And A.x<>D.x And D.s=2
Update B Set s=3 from B Inner Join Inserted D On B.id=D.id And B.s=2
End
End
else if(Inserted.s=3)
Begin
If Update(x)
Insert C Select E.id,GetDate(),'x',Rtrim(D.x)+' - '+Rtrim(E.x) from Deleted E Inner Join Inserted D On E.id=D.id And E.x<>D.x And D.s=3
End
End
GO
谢谢你的关注!!
我试了你的代码,没有问题.只是当我需要只更新B.s状态值后就要自动计算差异并写入C表的时候,那一段代码还有漏洞.
怎样实现如下功能的代码呢?
Create Trigger [Update_C]On B
FOR UPDATE
AS
Begin
if(Inserted.s=2)
Begin
If Update(x)
Begin
Insert C Select A.id,GetDate(),'x',Rtrim(D.x)+' - '+Rtrim(A.x) from A Inner Join Inserted D On A.id=D.id And A.x<>D.x And D.s=2
Update B Set s=3 from B Inner Join Inserted D On B.id=D.id And B.s=2
End
End
else if(Inserted.s=3)
Begin
If Update(x)
Insert C Select E.id,GetDate(),'x',Rtrim(D.x)+' - '+Rtrim(E.x) from Deleted E Inner Join Inserted D On E.id=D.id And E.x<>D.x And D.s=3
End
End
GO
#13
再顶一把!!
#14
"只更新B.s状态值后就要自动计算差异并写入C表",更改B的状态也要写入c表吗??
#15
谢谢 paoluo(一天到晚游泳的鱼)
是"在只更新B表的状态后也相应要分别计算对应x与y 的差异,如果有差异,则写入C表"
是"在只更新B表的状态后也相应要分别计算对应x与y 的差异,如果有差异,则写入C表"
#16
"在只更新B表的状态后也相应要分别计算对应x与y 的差异,如果有差异,则写入C表"
也就是说更改了x或y,才写入c表啊。
我写的例子中,如果x或y更改了,就会写入c表,没有问题啊。
难道说改了状态,状态的改变也要写入c表,还是指别的什么??
也就是说更改了x或y,才写入c表啊。
我写的例子中,如果x或y更改了,就会写入c表,没有问题啊。
难道说改了状态,状态的改变也要写入c表,还是指别的什么??
#17
paoluo(一天到晚游泳的鱼)
不好意思,两天都未得到时间来网上了.我确实是这样想的.如果使用这个触发器时,用户只简单更新了后面的一个状态值,我也希望它能把X与Y的值比对一下.
因为如果我没有做第一次比较,而是简单更新了状态,那么下一次再进行比较就会出现错误的结果.
不过问题总算解决了,我不用触发器方式,而是在更新B表的存储过程中比较,这样也较好控制.
谢谢你.paoluo(一天到晚游泳的鱼),谢谢你这么耐心的指教!
下面结贴.
不好意思,两天都未得到时间来网上了.我确实是这样想的.如果使用这个触发器时,用户只简单更新了后面的一个状态值,我也希望它能把X与Y的值比对一下.
因为如果我没有做第一次比较,而是简单更新了状态,那么下一次再进行比较就会出现错误的结果.
不过问题总算解决了,我不用触发器方式,而是在更新B表的存储过程中比较,这样也较好控制.
谢谢你.paoluo(一天到晚游泳的鱼),谢谢你这么耐心的指教!
下面结贴.