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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 NEW TO SQL

Author  Topic 

H
Starting Member

23 Posts

Posted - 2012-01-23 : 18:00:29
I am new to sql
Need help with 1 query

Table name:
1. Patient_master
Fields: patient_id, firstname, lastname, doctor_id, address,…..

2. case_master
Fields: case_id, case-no, description, start_date, case_start_date, doctor_id, ….

I want to make doctor_id from case_master equal to doctor_id on patient_master
(I mean replace doctor_id on case_master with doctor_id on Patient_master)

FYI
Emp_master has doctor_id and doctor first name , last name


I tired this but this did not help
update case_master, patient_master set case_master.doctor_id = patient_master.doctor_id


Thanks
H

Jaypoc
Yak Posting Veteran

58 Posts

Posted - 2012-01-23 : 18:53:52
In order to set the doctor ID's to match, you need to specify what you're matching based on.

UPDATE case_master
SET case_master.doctor_id = (SELECT doctor_id FROM patient_master WHERE patient_master.<somefield> = case_master.somefield)




Go to Top of Page

H
Starting Member

23 Posts

Posted - 2012-01-24 : 17:28:21
thanks for your reply
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-24 : 18:10:27
UPDATE m
SET Doctor_Id = p.Doctor_Id
FROM case_master m
JOIN patient_master p
ON m.key = p.key

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

H
Starting Member

23 Posts

Posted - 2012-01-24 : 23:19:44
thanks
Go to Top of Page
   

- Advertisement -