0

This might be a silly question. I have a staff table which stores staff Information. I need to get the salary for each staff. So I tried below queries

SELECT staffid, SUM(ISNULL(amount,0) +ISNULL(bonus,0)) as amount
from payments
group by staffid

But I got wrong output. Then I tried as below,

SELECT staffid, SUM(ISNULL(amount,0)) + SUM(ISNULL(bonus,0))
from payments
group by staffid

This time I got the correct output. But I wonder why the difference occurs. Does above two sum operations are different? someone please give some idea about this.

bmsqldev
  • 2,627
  • 10
  • 31
  • 65

0 Answers0