MichaelF81
Programmer
I am working on an update statement, and here is some background.
I am writing a DTS package and the first step is to import a txt file into a table called 'A_Imp' (well the first step is to make sure that 'A_Imp' is empty.).
Below is the table structure.
Now most of those fields are in the text file, but 'lname', 'fname' and 'dv_id' are not. My issue is the 'dv_id' field.
I need to pull the dv_id from the dv table, but there is no way to link the 'A_Imp' and 'dv' tables. There is a way to link the 'dp' and 'dv' table, and the 'dp' table can be linked to 'A_Imp' via 'dp_id'.
That is the code to link the two tables, but now I need to update the 'A_Imp.dv_id' field using that.
Any thoughts? Below is what I have gotten stuck at.
"Adults are just obsolete children and the hell with them." - Dr. Seuss
I am writing a DTS package and the first step is to import a txt file into a table called 'A_Imp' (well the first step is to make sure that 'A_Imp' is empty.).
Below is the table structure.
Code:
CREATE TABLE A_Imp (
full_name varchar (150) ,
em_id varchar (150) ,
dp_name varchar (150) ,
dp_id varchar (150) ,
job_title varchar (150) ,
u_std_desc varchar (150) ,
em_std varchar (150) ,
u_hiredate varchar (150) ,
lname varchar (150) ,
fname varchar (150) ,
dv_Id varchar (150)
)
Now most of those fields are in the text file, but 'lname', 'fname' and 'dv_id' are not. My issue is the 'dv_id' field.
I need to pull the dv_id from the dv table, but there is no way to link the 'A_Imp' and 'dv' tables. There is a way to link the 'dp' and 'dv' table, and the 'dp' table can be linked to 'A_Imp' via 'dp_id'.
Code:
Select afm.dv.dv_id, afm.dp.dp_id, afm.dv.[name]
from afm.dp inner join afm.dv on afm.dv[name] = afm.dp.[name]
That is the code to link the two tables, but now I need to update the 'A_Imp.dv_id' field using that.
Any thoughts? Below is what I have gotten stuck at.
Code:
update A_Imp
set A_Imp.dv_id = (select afm.dv.dv_id from afm.dv inner join afm.dp on afm.dp.[name] = afm.dv.[name])
where A_Imp.dp_id = afm.dp.dp_id
GO
"Adults are just obsolete children and the hell with them." - Dr. Seuss