I have a table that reuses a foreign key and I’d like to join a different value for each case. The first table describes a drug dosing activity. It has ID’s that point to drugs, routes, vehicles, etc… The confusing thing is that it reuses the Unit ID which is a foreign key in a single description table.
GROUPS (Simplified)
GROUP_NO DRUG DRUG_AMOUNT DRUG_UNIT CHECK_UNIT
1 568 5 7 5
2 689 1 7 5
2 568 5 7 5
3 19 0.5 10
4 984 10 10 5
UNITS (Simplified)
UNIT_ID UNIT_DESCR
5 kg
7 mg
10 mL
I’d like to generate a query that returns a row for each drug dose for all groups. I can do everything but the units. I’d like to use a CASE statement to display the dosing units. The select statement would look something like this:
'DOSE UNITS' =
CASE
WHEN CHECK_UNIT IS NULL THEN DRUG_UNIT_DESCR
ELSE CONCAT(DRUG_UNIT_DESCR+'/'+CHECK_UNIT_DESCR)
END
I’m trying to get the results to look like such for this example:
RESULT
GROUP_NO DRUG DRUG_AMOUNT 'DOSE UNITS'
1 HelpsAlot 5 mg/kg
2 HelpsMore 1 mg/kg
2 HelpsAlot 5 mg/kg
3 DoesNothing 0.5 mL
4 WhoKnows 10 mL/kg
Thanks for any help.
You need two joins, one for each key: