Elegant Solution re MTM Relationship?
Posted in 1994
Topics: SQL Development & Query Writing, Connectivity: ESQL/C, 4GL & Embedded SQL
I'd appreciate an elegant solution for the problem below... We're using Informix SE, 4GL, C on UNIX platforms, but imho the problem is general enough that these specifics don't matter. We have one table consisting of a single field, I'll call it "HC" for "header code". Another table contains order codes ("OC"). There is a many-to-many relationship between order codes and header codes. The proper header code needs to be determined by the number and value of non-repeating order codes. I can make a table with a single HC attribute and a single OC attribute, the combination will be unique. I could prepare a possibly horrendous sql query to solve this but am hoping for something more elegant. As an example: HC "ABC" contains OC's "ABC","DEF", and "GHI" HC "ABD" contains OC's "ABC" and "DEF" HC "ABE" contains OC's "ABC", "DEF", "GHI", "XYZ" The input to my program will be an indefinite number of OC's. I'll need to output the proper HC value. My best-so-far solution is to hash the OC's for a specific HC and then store the resulting integer value in the headercodes table. I'll need to have an alternate hashing algorithm and an indicator in the headercodes table for which algorithm was used. I'll also have to double-check whatever hash value I get from the incoming OC's since there's certainly the possibility that no HC's would be applicable. All changes to the headercodes table will be under program control (presumably), thus I can keep the hash value updated as things change. However, I'm hoping for a pure db design or SQL solution. If anybody has any ideas, I'd appreciate it. Please post or email... Thanks, -Mike -- | o==== . : ... : : . |Mail Me Neat $tuff->POB 3703 Arlington VA 22203 --@-- . o o o ... O -O- o o : | mwiik@netcom.com | ... : : |----------------------------------------------- mEssAGE fRoM sPAcE ARt stUdiOs | Plot Globally Attack Locally