nickdaniels
MIS
I am having a problem generating accurate sql in the following situation. We have accounts which may be have one of a number of statii. An account may be rejected, in which case a single record with a statuscode of 'R' will be held in the table.<br><br>An account may be accepted stage 1, in which case the 'applicationstage' field in the table will be 1. Alternatively, the account may be accepted stage 2, in which case the 'applicationstage' field will be 2.<br><br>So, I can indentify rejections and stage 2s no problem.<br><br>However, due to the fact that the 'history' of the account is held in the table, if I do a straight decode application stage to get the stage1 total, I include within this total any stage 1s that have now moved to stage 2. These should only be counted as stage 2, but my sql is counting them twice.<br><br>Below is the SQL I am using - first checking that it isn't a rejection<br><br>COUNT(DISTINCT(decode(LOANAPPLICATION.STATUSCODE,'R',0,decode(LOANAPPLICATION.APPLICATIONSTAGE,1,LOANAPPLICATION.ACCOUNTID))))<br><br>I don't know how to also get this statement to check for records with the same account number with a status of 2.<br><br>All help appreciated! cheers, Nick