I have created a query for updating a table from another table. The field is updating as expected for a given date. The problem is that for other dates, I am now getting NULL values on the column I updated. How do I set the new value only for the specific date and not affect the other dates?
Table A:
| ID | VALUE | ADD_TIME |
-------------------------------------
| 1 | -5 |1/11/2019 10:45:11 am |
Table B:
|AS_OF_DATE| ID | VALUE |
-------------------------
|2/29/2019 | 1 | -4 |
|1/31/2019 | 1 | -4 |
|12/31/2018| 1 | -4 |
Desired Output:
|AS_OF_DATE| ID | VALUE |
-------------------------
|2/29/2019 | 1 | -4 |
|1/31/2019 | 1 | -4 |
|12/31/2018| 1 | -5 |
Current Output:
|AS_OF_DATE| ID | VALUE |
-------------------------
|2/29/2019 | 1 | |
|1/31/2019 | 1 | |
|12/31/2018| 1 | -5 |
My Query:
update TABLEB
set VALUE =
(
select VALUE from TableA
where ID = '1'
and TABLEB.AS_OF_DATE < TABLEA.ADD_TIME
)