I am having difficulty with this stored procedure. I am hoping there are most experts than myself that can put this together. I seem to be drawing a blank.

The criterias are as follows:

when reserve_type_code = 369 then
paid_total = IndemnityPaid
collection_total = IndemnityCollected
reserve_amount = IndemnityReserve
incurred_amount = IndemnityIncurred

when reserve_type_code = 368 then
paid_total = ExpensesPaid
collection_total = ExpensesCollected
reserve_amount = ExpensesReserve
incurred_amount = ExpensesIncurred

NetIndemnity = IndemnityPaid - IndemnityCollected
If IndemnityReserve> NetIndemnity then GreaterIndemnity = IndemnityReserve
If IndemnityReserve< NetIndemnity then GreaterIndemnity = NetIndemnity

NetExpenese = ExpenesePaid - ExpensesCollected
If ExpensesReserve> NetExpenses then GreaterExpenses = ExpensesReserve
If ExpensesReserve< NetExpenses then GreaterExpenses = NetExpenses

If GreaterIndemnity + GreaterExpenses > 500,000, then I need the claim_id to return to my program

The table is one-to-many

Please help!!!