谁来帮我改下这个触发器啊 懂触发器的请进
表 [产品] 里有 [产品ID] [产品数量] [断货时间] 等字段
断货时间 与 产品数量 的关系是
当 产品数量<=0 时 断货时间=getdate()
当 产品数量>0 时 断货时间=null
下面是我写的触发器 当然是错的 希望高手帮忙改正
CREATE TRIGGER [uptime] ON [产品]
FOR INSERT, UPDATE
AS
declare @stock int
declare @stime datetime(8)
set @stock=(select 产品数量 from 产品),
set @stime=(select 断货时间 from 产品),
if (@stock<=0 and isdate(@stime)=0)
begin
update 产品 set 断货时间=getdate()
end
if (@stock>0 and isdate(@stime)=1)
begin
update 产品 set 断货时间=null
end
这是第二次发问了
原先问题:
表A里有字段A1 A2
A1是数据类型的,大小会随时变化
A2根据A1求值
当A1<=0 并且A2要为空(不希望A2变化) 时A2等于此时的时间,以后不再改变除非A1>0
当A1>0时 A2为空
我是这样写的
case when a1<=0 and isdate(a2)=0 then getdate() else '' end
这是错的 因为a2不能包含在自己的公式里
求正确的答案
http://community.csdn.net/Expert/topic/4980/4980679.xml?temp=.1334497