Reputation: 1259
I am writing a very simple UPDATE query but it doesnt update cardbalance
field.
update cardbalance
set CardBalance = CardBalance + 1000, TotalLoading= TotalLoading+356, Totalredemption = Totalredemption + 256
where pan = '20000002'
I checked the CardBalance
field and it was NULL
. Is it because of this? Whats the solution?
Upvotes: 0
Views: 37
Reputation: 751
you are trying to add 1000 to a null value that is why it returns always null. use the ISNULL function to put a value of 0 when CardBalance is null. The query should be something like this:
update cardbalance
set CardBalance = isnull(CardBalance,0) + 1000, TotalLoading= TotalLoading+356, Totalredemption = Totalredemption + 256
where pan = '20000002'
Upvotes: 0
Reputation: 19
Try this.
UPDATE cardbalance
SET CardBalance = ISNULL(CardBalance,0) + 1000, TotalLoading= TotalLoading+356, Totalredemption = Totalredemption + 256
WHERE pan = '20000002'
Upvotes: 0
Reputation: 2490
If CardBalance is NULL then adding 1000 to it will give as NULL, so you may put an ISNULL to find if NULL and make it as 0(or something you want to).
update cardbalance
set CardBalance = ISNULL(CardBalance,0) + 1000,
TotalLoading= TotalLoading+356,
Totalredemption = Totalredemption + 256
where pan = '20000002'
Upvotes: 2