If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > SQL statement giving me trouble

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-16-07, 11:46
tpoettker tpoettker is offline
Registered User
 
Join Date: May 2004
Posts: 13
SQL statement giving me trouble

I have a table with the following fields
ClaimID
IndemnityPaid
IndemnityCollected
IndemnityReserved
IndemnityIncurred
NetIndemnity
ExpensesPaid
ExpensesCollected
ExpensesReserved
ExpensesIncurred
NetExpenses

I need to find the claimID when total Indemnity + Expenses > 500000
Indemnity will equal the greater of IndemnityReserved or NetIndemnity
Expenses will equal the greater of ExpensesReserved or NetExpenses

I don't know how to put this into a sql statement. Would this be in the where conditions as a case or what???
Reply With Quote
  #2 (permalink)  
Old 02-16-07, 12:29
RedNeckGeek RedNeckGeek is offline
Village Idiot
 
Join Date: Jul 2003
Location: Michigan
Posts: 1,941
Depending on whether your platform supports CASE construct
(Access doesn't)

Code:
SELECT CLAIMID, 
'INDEMNITY' = CASE WHEN INDEMNITYRESERVED>NETINDEMNITY THEN INDEMNITYRESERVED ELSE NETINDEMNITY END,
'EXPENSES'=  CASE WHEN EXPENSESRESERVED>NETEXPENSES THEN EXPENSESRESERVED ELSE NETEXPENSES END
FROM #TMPCLAIMS
WHERE (CASE WHEN INDEMNITYRESERVED>NETINDEMNITY THEN INDEMNITYRESERVED ELSE NETINDEMNITY END + CASE WHEN EXPENSESRESERVED>NETEXPENSES THEN EXPENSESRESERVED ELSE NETEXPENSES END)>500000
Of course, you don't need to include INDEMNITY and EXPENSES in the SELECT statement, I just put it there so you could see the values it would pull. You can delete that, and just leave the WHERE clause as is.
__________________
Inspiration Through Fermentation
Reply With Quote
  #3 (permalink)  
Old 02-16-07, 13:11
tpoettker tpoettker is offline
Registered User
 
Join Date: May 2004
Posts: 13
thank you. it worked.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On