如何使数字字段不接受负值 [英] how to make numeric field not accept negative value

查看:102
本文介绍了如何使数字字段不接受负值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果更新字段如

它有10.0



现在我减少了11.0

它不会更新它

and if update the field like
it has 10.0

nd now i reduce it by 11.0
it will not update it

推荐答案

检查约束 [ ^ ]



编辑

------------------------

更新前,检查计算是否产生负值。如果为负,则引发异常,否则进行更新。下面的示例。

这里我们在更新前检查StockQty

CHECK Constraint[^]

EDIT
------------------------
Before update, check the calculation produces the negative value or not. If negative, raise exception else do update. Sample below.
Here we're checking the StockQty before update
SET @StockQty = SELECT StockQty FROM TblStock WHERE ItemID = 'SomeItemID';

IF @StockQty < @RequiredQty -- @RequiredQty value from your code as parameter to stored procedure
BEGIN
     PRINT 'Stock Qty is less than Required Qty' --Add exception block here based on your requirement
END
ELSE
BEGIN
     UPDATE TblStock SET StockQty=StockQty-@RequiredQty WHERE ItemID = 'SomeItemID';
END 



通过上述相同的逻辑,您可以在前端执行此操作。


By the above same logic, you could do this in front end.


只检查(当前值) - (新值)> = 0然后更新else什么都不做
just check if the (current value) - (new value) >= 0 then update else do nothing


这篇关于如何使数字字段不接受负值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆