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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Comparing two tables

Author  Topic 

satya068
Posting Yak Master

233 Posts

Posted - 2010-08-09 : 05:50:45

I am looking to get sql script to the below query,

i have two table in my databases APPOINTMENTS and ADMISSIONS in admissions table there are 4000 records where i need to replace REFERRAL_DATE column in ADMISSIONS with APPOINTMENT_DATE column from APPOINTMENTS table,KEY_CODE is the common column in both table.

for the 4000 records in ADMISSIONS table if the key_code matches with key_code in APPOINTMENTS table then for that record the data in the column REFERAL_DATE needs to replace with APPOINTMENT_DATE from Appointments table.

if u have any idea about this script please let me know.

thanks

Satya

PavanKK
Starting Member

32 Posts

Posted - 2010-08-09 : 06:18:44

UPDATE AD
SET AD.REFERAL_DATE = AP.APPOINTMENT_DATE
FROM ADMISSIONS AD
JOIN APPOINTMENTS AP ON AD.KEY_CODE = AP.KEY_CODE



KK
Go to Top of Page

satya068
Posting Yak Master

233 Posts

Posted - 2010-08-09 : 06:33:51
Thanx pavan,
i am sorry, i forgot to mention that appointments in EMP_DB(database)and admissions table in ADM_DB ,can you help me in wrinting the sql from two diff databases.
quote:
Originally posted by PavanKK


UPDATE AD
SET AD.REFERAL_DATE = AP.APPOINTMENT_DATE
FROM ADMISSIONS AD
JOIN APPOINTMENTS AP ON AD.KEY_CODE = AP.KEY_CODE



KK



Satya
Go to Top of Page

PavanKK
Starting Member

32 Posts

Posted - 2010-08-09 : 06:43:42
Try thhis


UPDATE AD
SET AD.REFERAL_DATE = AP.APPOINTMENT_DATE
FROM ADM_DB..ADMISSIONS AD
JOIN EMP_DB..APPOINTMENTS AP ON AD.KEY_CODE = AP.KEY_CODE



KK
Go to Top of Page

satya068
Posting Yak Master

233 Posts

Posted - 2010-08-09 : 07:02:31
its worked.
Thanx for ur help pavan.


quote:
Originally posted by PavanKK

Try thhis


UPDATE AD
SET AD.REFERAL_DATE = AP.APPOINTMENT_DATE
FROM ADM_DB..ADMISSIONS AD
JOIN EMP_DB..APPOINTMENTS AP ON AD.KEY_CODE = AP.KEY_CODE



KK



Satya
Go to Top of Page
   

- Advertisement -