Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SELECT question
Message
De
03/04/1998 10:23:58
Shane Gilbert
Oklahoma State Department of Education
Norman, Oklahoma, États-Unis
 
 
À
03/04/1998 10:15:05
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00089237
Message ID:
00089257
Vues:
20
>>I have a table with about 16000 records in it. These are monthly claims. The table contains original, and revised claims. The original claims have claims.crecno = 0, and each revision to that claim increments the crecno by 1. So for any month, there is an original and from 0 to many revisions. I want a SELECT that I can retrieve the latest revised claims for a given month into a cursor. So that if the client just sent in the original(crecno=0) I get the original claim, but if there are any revisions, I get the claim with the highest(crecno).
>>Table: claims
>>co n2
>>dist c4
>>month n2
>>year n4
>>crecno n2
>>data...
>>
>>str(co,2)+dist is the customer number
>>
>>I want something like:
>>SELECT * FROM claims WHERE month = 12 AND year = 1997 AND Max(crecno);
>>INTO CURSOR claimlist
>>
>>Any suggestions?
>>
>>Shane
>Shane,
>I think you should do it in two SQL.
>
>select str(co,2)+dist, ;
>       str(co,2)+dist+padl(crecno,2,"0") as identifier ,;
>       max(crecno) ;
>  from claims ;
>  WHERE month = 12 AND year = 1997 ;
>  group by 1 ;
>  where .t. ;
>  into cursor pass1
>SELECT * FROM claims ;
>  WHERE str(co,2)+dist+padl(crecno,2,"0") in ;
>       (select identifier from pass1) ;
>       INTO CURSOR claimlist
>
>Cetin

Thanks for the answer, I'll give that a try. I tried the following and seemed to get the correct results, but I wonder if I am missing something that will bite me later:

SELECT *,MAX(crecno) AS last;
FROM claims;
WHERE month = 12 AND year = 1997;
GROUP BY co,dist;
ORDER BY co,dist;
INTO CURSOR claimlist

Thanks again for the help

Shane
--Shane
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform