I have two tables t1 and t2 basically, t1 contains code 3299 against ind_ref 86034 where t2 is missing that code. I want to do an insert in t2 and get the code 3299 from t1 .
here is t1
IND_REF Code
86034 3299
here is t2
IND_REF Code
86034 1212
I want to see the output as
IND_REF Code
86034 1212
86034 3299 <-- as insert from t1
How can i achieve this,
Here is my query, but it doesnt update.
INSERT INTO test.DBO.ATTRIBUTE (ATTR_CODE_REF)
select ((SELECT att.ATTR_CODE_REF
FROM individual ind
join contact c on c.individual_ref=ind.individual_ref
join organisation org on org.organisation_Ref=c.ORGANISATION_REF and c.main_organisation='y' and c.valid_to is null --contact_ref
join attribute att on att.organisation_ref=org.organisation_ref and att.code_type=3299
where iND.individual_ref=86034))--@indref)
from ATTRIBUTE
WHERE ATTRIBUTE.INDIVIDUAL_REF=86034