UFN_OPPORTUNITY_AMOUNT
Calculates the total amount of an Ask.
Return
| Return Type |
|---|
| money |
Parameters
| Parameter | Parameter Type | Mode | Description |
|---|---|---|---|
| @ID | uniqueidentifier | IN |
Definition
Copy
CREATE function dbo.UFN_OPPORTUNITY_AMOUNT(@ID uniqueidentifier)
returns money
with execute as caller
as begin
return
-- Outer coalesce in case of bad @ID
coalesce(
(
select
case when STATUSCODE = 3 then -- Accepted
coalesce(ACCEPTEDASKAMOUNT,
(
select
sum(AMOUNT)
from
dbo.OPPORTUNITYDESIGNATION
where
OPPORTUNITYID=@ID
),
0
)
else
case when ASKAMOUNT > 0 then ASKAMOUNT
else EXPECTEDASKAMOUNT
end
end
from
dbo.OPPORTUNITY
where
ID = @ID
),
0
)
end