Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
and if update the field like
it has 10.0

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

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
SQL
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.
 
Share this answer
 
v2
Comments
Abhijeet pratap singh 23-Nov-13 7:36am    
but his is the solution when create table
bur i have already created the table
and i am using SqlServer 2008
thatraja 23-Nov-13 7:50am    
Check updated answer
just check if the (current value) - (new value) >= 0 then update else do nothing
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900