Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
Posted - 2009-09-04 : 11:46:43
|
| I get this error when i execute this code. could you help me?Msg 4104, Level 16, State 1, Line 3The multi-part identifier "b.encounterid" could not be bound.drop table encountergodrop table patientgodrop table appointment gocreate table patient (patientID int primary key identity(1,1), patientName varchar(50), clientID int)create table encounter (encounterID int primary key identity(1,1), EncounterName varchar(50), hospitalID int, PatientID int references patient(PatientID))create table appointment (appointmentID int primary key identity(1,1), HospitalID int, appointmentDate datetime )insert patientselect 'FeeFee', 100 union allselect 'Max', 100 union allselect 'Bones', 100 union allselect 'Fort', 100 insert encounterselect 'Enc - Daniel', 10, 1 union allselect 'Enc - Jose', 10, 2 union allselect 'Enc - Mary', 11, 3 union allselect 'Enc - Luis', 11, 4 insert appointmentselect 12, getdate()-5 union allselect 1, getdate()-3 union allselect 10, getdate()-10select * from patientselect * from encounterselect * from appointmentselect a.appointmentid, b.encounterid from appointment awhere exists (select b.encounterid from encounter b where a.hospitalID = b.hospitalID and b.patientID in (select patientID from patient where clientID = 100)) |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-09-04 : 11:56:00
|
You cannot use columns from a WHERE-EXISTS-SELECT in the outer query. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-09-04 : 11:56:43
|
may be u need this?select a.appointmentid,b.encounterid from appointment ainner join encounter b on a.hospitalID = b.hospitalIDinner join patient c on b.patientID = c.patientIDwhere c.clientID = 100 |
 |
|
|
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
Posted - 2009-09-09 : 11:31:57
|
| thanks |
 |
|
|
|
|
|
|
|