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 |
|
sross81
Posting Yak Master
228 Posts |
Posted - 2008-05-27 : 11:04:12
|
| Hello,I have an existing table that many fields are missing some information that must be obtained by comparing a code to another existing table and then updating the main table.Here is my code to determine which lab tests are missing table_name and field_name data.select distinct a.*from lab_test_add_conf ajoin emr_temp_labtest_configupdate b on a.labtest_key = b.labtestcodejoin emr_zseg_code_descriptions c on b.zsegcode = c.zsegcodewhere a.table_name = ' ' and a.field_name = ' 'The emr_zseg_code_descriptions table contains the actual data that must be inserted into the lab_test_add_conf columns for field_name and table_name joined on zsegcode. I have never set up an update statement that has to deal with joins. Does anyone have a good way to set this up??Thanks! :) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-27 : 11:07:11
|
| [code]update aset a.table_name=c.table_name, a.field_name=c.field_namefrom lab_test_add_conf ajoin emr_temp_labtest_configupdate b on a.labtest_key = b.labtestcodejoin emr_zseg_code_descriptions c on b.zsegcode = c.zsegcodewhere a.table_name = ' ' and a.field_name = ' '[/code]I'm assuming field names are same in emr_zseg_code_descriptions & lab_test_add_conf tables |
 |
|
|
sross81
Posting Yak Master
228 Posts |
Posted - 2008-05-27 : 11:11:33
|
As always you are so helpful!! :) Thanks so much. :)quote: Originally posted by visakh16
update aset a.table_name=c.table_name, a.field_name=c.field_namefrom lab_test_add_conf ajoin emr_temp_labtest_configupdate b on a.labtest_key = b.labtestcodejoin emr_zseg_code_descriptions c on b.zsegcode = c.zsegcodewhere a.table_name = ' ' and a.field_name = ' ' I'm assuming field names are same in emr_zseg_code_descriptions & lab_test_add_conf tables
|
 |
|
|
|
|
|