jello
jello

Reputation: 745

The multi-part identifier could not be bound

I have this very simple sql statement:

SELECT     max_dose
FROM         psychotropes
WHERE     (patient_meds.psychotrope = psychotrope_name) AND (patient_meds.patient_id = 12)

when I try to run it in Visual Studio 2008, it tells me "The multi-part 'patient_meds.psychotrope' identifier could not be bound"

it's weird, because I did set a relationship between the two tables in the diagram viewer

Upvotes: 15

Views: 34205

Answers (2)

Dustin Laine
Dustin Laine

Reputation: 38503

You are not including the table in the query. Without knowing the schema this is just an assumption. Also a database diagram does nothing to assist in queries.

SELECT ax_dose
FROM psychotropes
INNER JOIN patient_meds ON psychotropes.psychotrope_name = patient_meds.psychotrope
WHERE (patient_meds.patient_id = 12)

Upvotes: 9

codaddict
codaddict

Reputation: 455030

I guess you'll have to include patient_meds in the table list as:

FROM psychotropes, patient_meds

Upvotes: 16

Related Questions