I am needing to find a way to SUM()
all of the positive values for num
and return the SUM()
of all positive numbers and an individual row for each negative number. Below is a sample DDL:
Create Table #Be
(
id int
, salesid int
, num decimal(16,4)
)
Insert Into #BE Values
(1, 1, 12.32), (2, 1, -13.00), (3, 1, 14.00)
, (4, 2, 12.12), (5, 2, 14.00), (6, 2, 21.23)
, (7, 3, -12.32), (8,3, -43.23), (9, 3, -2.32)
And this is my desired output (positive numbers for each salesid SUM()
and negatives get an individual line returned):
salesid num
1 26.32
1 -13.00
2 47.35
3 -12.32
3 -43.23
3 -2.32