Re: MER - complicated join

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Mon, 5 Nov 2007 17:59:00 -0800, mark r <markr@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote:

I am going to need lots of help and patients with this one.

I think my basic question is:

How do I set up a join so that my main table can get prices attached to it
for 4 different fields which hold the same data type?

I have received error messages such as: Ambiguous join error . . . . . .it
tells me to create a separate query and then include that query in the sql -
- - I don't know even how to do a separate query. Can you break this down
into small steps with explanations please. cell phone: 954-234-4239

The main data table ENCOUNTER which has fields
proc_code
proc_code1
proc_code2
proc_code3

the pricing for these codes reside in table named procedurecodes
and the 3 fields in PROCEDURECODES are:
procedure fees description

So each record in ENCOUNTER has up to 4 codes populated.
I need to run a query which will result in a price for each proc_cod.

Thus
record 1 proc_code 55788 proc_code1 55899 proc_code2
55898


Your table structure IS WRONG.

If you have four codes today, someday you'll need five... or six. You have a
many (encounters) to many (procedures) relationship! The proper way to model
this is with three tables:

Encounters
RecordNo
<information about the encounter as a whole>

Procedures
Proc_Code (Primary Key)
Cost (currency)
<other information about the procedure)

ProceduresUsed
RecordNo <link to Encounters>
Proc_Code <link to Procedures>

You can then add two, or four, or seven procedures to the ProceduresUsed
table; do a very simple Totals query to sum the costs; use a Crosstab query if
you need the "many fields" view for display or export to a spreadsheet; very
simply search for which procedures were in which encounters; etc.

should RESULT IN:
record 1 proc_code 55788 $74 proc_code1 55899 $86 proc_code2 55898
$120. . . .etc


So if I do a standard join I drop records.
Below is the code I used.

below is some code I started using



FROM UPIN, HCFA_ADD_FAC32, HCFA_ADD_SUP33, PROVIDERTAXID, procedurecodes AS
procedurecodes_1 INNER JOIN (procedurecodes INNER JOIN ((ALF INNER JOIN
pt_ALF ON ALF.ALFid = pt_ALF.ALFid) INNER JOIN (encounter INNER JOIN
diagnosis ON encounter.diagcode = diagnosis.diagcode) ON pt_ALF.ID_pt_ALF =
encounter.ID_pt_ALF) ON procedurecodes.procedure = encounter.proc_code) ON
procedurecodes_1.procedure = encounter.proc_code2

With your current spreadsheetish structure you'll need to join the procedures
table *FOUR TIMES*, once to each Proc_Code field, all using Left Outer Joins
rather than inner joins.

You'll have exactly the same problem with your diagnosis codes, unless each
encounter/patient has one and only one diagnosis.

John W. Vinson [MVP]
.



Relevant Pages

  • Re: MySQL Query Optimization
    ... > query can take 15 seconds or more for broader searches. ... What you really need is a precomputed table of distances between zip codes. ... any location in one block is within distance of any location in the other). ... The distance table would consist of pairs of three-digit zones that meet ...
    (comp.lang.php)
  • Re: Command Button to modify a table
    ... Dim strSql As String ... You can mock up a query based on this Counter table, turn it into an Append query, and switch to SQL View to get an example of the query string you need to create. ... this number would be used to create 43 unique codes. ...
    (microsoft.public.access.forms)
  • Nested Looping SQL Querys
    ... SQL Querys are stored in the .py files and run in the .cgi files. ... the first query results are delimited with and the second with I ... def creationSQL(pubID, productCode, description, suppNo1, all): ... # Return list of checked product codes. ...
    (comp.lang.python)
  • Re: update query for multiple changes to a single field
    ... same query and just modify the query for each change. ... criteria for call_type and reset Update TO for the next change. ... Applications ... i want to do a single pass update that will change the codes to: ...
    (microsoft.public.access.queries)
  • Re: Split a string in one field into two fields
    ... single field, you can use a query to get the other parts. ... My second problem is that for some reason most the Zip codes that started ... you won't be doing any math on them, so don't store them as numbers ... ...
    (microsoft.public.access.reports)