导航
  • 主页
  • 基础类
  • 应用实例
  • 新技术前沿

当数值为<null>时,触发器不运算,怎么办?

tongbang 2003-12-09 02:40:37


CREATE TRIGGER ZJC_OUT3 ON dbo.zjc_out
FOR INSERT, UPDATE, DELETE
AS

SET NOCOUNT ON

UPDATE zjc_plan
SET out_num=zjc_plan.out_num-deleted.out_num
FROM zjc_plan,deleted
WHERE zjc_plan.materials_code=deleted.materials_code and zjc_plan.contract=deleted.contract

UPDATE zjc_plan
SET out_num=zjc_plan.out_num+inserted.out_num
FROM zjc_plan,inserted
WHERE zjc_plan.materials_code=inserted.materials_code and zjc_plan.contract=inserted.contract

SET NOCOUNT OFF



...全文
12 点赞 收藏 7
写回复
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
klan 2003-12-09
在存储过程中不是一样用啊?
回复
Coolyu0916 2003-12-09
是不是不允许空值得插入或者更新??
回复
dlpseeyou 2003-12-09
case when .....
else ..... end
回复
tongbang 2003-12-09
在触发器中,不知道怎么用?
回复
LoveSQL 2003-12-09
CREATE TRIGGER ZJC_OUT3 ON dbo.zjc_out
FOR INSERT, UPDATE, DELETE
AS

SET NOCOUNT ON

UPDATE zjc_plan
SET out_num=isnull(zjc_plan.out_num,0)-isnull(deleted.out_num,0)
FROM zjc_plan,deleted
WHERE zjc_plan.materials_code=deleted.materials_code and zjc_plan.contract=deleted.contract

UPDATE zjc_plan
SET out_num=isnull(zjc_plan.out_num,0)+isnull(inserted.out_num,0)
FROM zjc_plan,inserted
WHERE zjc_plan.materials_code=inserted.materials_code and zjc_plan.contract=inserted.contract

SET NOCOUNT OFF
回复
klan 2003-12-09
Replaces NULL with the specified replacement value.
Syntax

ISNULL(check_expression, replacement_value)

Arguments

check_expression

Is the expression to be checked for NULL. check_expression can be of any type.

replacement_value

Is the expression to be returned if check_expression is NULL. replacement_value must have the same type as check_expresssion.

Return Types

Returns the same type as check_expression.

Remarks

The value of check_expression is returned if it is not NULL; otherwise, replacement_value is returned.
回复
klan 2003-12-09
用isnull函数试试

回复
发动态
发帖子
MS-SQL Server
创建于2007-09-28

3.2w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
社区公告
暂无公告