Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stored procedure help

Status
Not open for further replies.

lllyxer

Programmer
Nov 22, 2006
22
US
I have a table FEES.
It has columns like fee_id, return_code,fee_source , application_fee, approval_fee and denial_fee
I need to create a stored procedure that will get SUM of application_fee and SUM of approval or denial fee(see logic below) .

The trick here is to get the right field based on following logic:
If return_code = 0 AND fee_source =1 I need to have an approval_fee in SELECT clause
If return_code <> 0 AND fee_source =1 I need to have an denial_fee in SELECT clause

Thanks for your help
 
Code:
SELECT .....
       SUM(CASE WHEN return_code = 0 AND fee_source = 1 THEN
                     approval_fee
                WHEN return_code <>0 AND fee_source = 1 THEN
                     denial_fee
           END) AS SUmField
.....

And because thi doesn't seems to be right, to me:
Code:
SELECT .....
       SUM(CASE WHEN return_code = 0 AND fee_source = 1 THEN
                     approval_fee
                ELSE 0 END) AS ApprSum,
       SUM(CASE WHEN return_code <> 0 AND fee_source = 1 THEN
                     denial_fee
                ELSE 0 END) AS DenySum
.....

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top