I was wondering if the following was possible:
I have 2 tables.
Table OEORDD
Fields - ORDUNIQ, LINENUM, EXPDATE (among other field but they are not relevant)
Table OEORDHO
Fields - ORDUNIQ, VALUE (among other field but they are not relevant)
Is it possible to have table OEORDD be updated based on Table OEORDHO
I was able to do it when Table OEORDHO only had one field, but I can't seem to do it when it has more.
The data I need is from the following query:
select OPTFIELD,VALUE from OEORDHO where OPTFIELD = 'REQUIREDDATE' and value <> 0 Which needs to update each EXPDATE on table OEORDD matching the VALUE from Table OEORDHO.
Select ORDUNIQ,LINENUM,EXPDATE from OEORDD where ORDUNIQ in ( select ORDUNIQ from OEORDHO where OPTFIELD = 'REQUIREDDATE' and value <> 0) I tried this, but it returns an error:
update ACCPACAU.dbo.OEORDD set EXPDATE = (select VALUE from OEORDHO where OPTFIELD = 'REQUIREDDATE' and value <> 0) where ORDUNIQ in ( select ORDUNIQ from OEORDHO where OPTFIELD = 'REQUIREDDATE' and value <> 0) Here is some sample data and what I want it to look like. With that in mind, there will be more and more dates coming, so I need it to be to expand if that makes sense.
Table OEORDHO data:
+----------+----------+ | ORDUNIQ | VALUE | +----------+----------+ | 21466890 | 20210920 | +----------+----------+ | 21472824 | 20220101 | +----------+----------+
Table OEORDD data:
+----------+---------+----------+ | ORDUNIQ | LINENUM | EXPDATE | +----------+---------+----------+ | 21466890 | 32 | 20190920 | +----------+---------+----------+ | 21472824 | 32 | 20210716 | +----------+---------+----------+ | 21472824 | 96 | 20210416 | +----------+---------+----------+ | 21472824 | 64 | 20210516 | +----------+---------+----------+
What I need table OEORDD to look like:
+----------+---------+----------+ | ORDUNIQ | LINENUM | EXPDATE | +----------+---------+----------+ | 21466890 | 32 | 20210920 | +----------+---------+----------+ | 21472824 | 32 | 20220101 | +----------+---------+----------+ | 21472824 | 96 | 20220101 | +----------+---------+----------+ | 21472824 | 64 | 20220101 | +----------+---------+----------+