|
I'm new at SQL and would like for someone to please tell me if this statement will do what I want. The PRDHIST file has duplicate keys and is keyed on PHGRP, PHACCT, PHSSN, PHPRID. The COVMSTR is keyed on CVSSN CVGRP and CVACCT and it is a unique key. PHPRID is a product ID and a person could have many products and many different periods of coverage. I want to join the PDTHIST with COVMSTR and pick up as many fields as I need from the two files. I ordered it by the keys from PDTHIST plus the termination date in descending order. (all records have termination dates and only future dates are active records. I would like for the distinct fields to be PHGRP PHACCT PHSSN PHPRID but the SELECT statement seems to force you to list all fields that you want to use. Can I restrict the DISTINCT fields to only certain fields but still pick up other fields for use later in my program?. Is the WHERE statement used to join the files so you would always join the two files with the keys and then add any additional requirements/restrictions? Any and all suggestion are greatly appreciated and please suggest a good reference manual if you know of one. Thanks in advance. EXEC SQL DECLARE COBRA_CUR CURSOR FOR SELECT DISTINCT A.PHGRP, A.PHACCT, A.PHSSN, A.PHEDCY, A.PHEDYR, A.PHEDMT, A.PHEDDY, A.PHTDCY, A.PHTDYR, A.PHTDMT, A.PHTDDY, A.PHPRID, A.PHTRFC, A.PHGGAO, B.CVTRCD FROM PDTHIST A, COVMSTR B WHERE (A.PHGRP = B.CVGRP) AND (A.PHSSN = B.CVSSN) AND (A.PHACCT = B.CVACCT) AND (A.PHTRFC = :COBPO OR A.PHTRFC = :COBPS OR A.PHTRFC = :COBPC OR A.PHTRFC = :COBPF OR A.PHTRFC = :COBCO) AND (DIGITS(A.PHTDCY)||DIGITS(A.PHTDYR)|| DIGITS(A.PHTDMT)||DIGITS(A.PHTDDY) > :TODAYS-DATE) ORDER BY A.PHGRP, A.PHACCT, A.PHSSN, A.PHPRID, A.PHEDCY DESC, A.PHEDYR DESC, A.PHEDMT DESC, A.PHEDDY DESC END-EXEC. +--- | This is the Midrange System Mailing List! | To submit a new message, send your mail to MIDRANGE-L@midrange.com. | To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com. | To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.