Q:

UPDATE a Table with the smallest date between 2 tables

I have 2 Tables:
@Temdate1 
+------+------------+---------------+--------+
| Year | Entry_Date | DeliveryMonth | Symbol |
+------+------------+---------------+--------+
| 2016 | 2016-01-07 | June          | ABC    |
| 2015 | 2015-01-06 | June          | ABC    |
| 2014 | 2014-01-05 | June          | ABC    |
| 2016 | 2016-03-05 | Sep           | CDE    |
| 2015 | 2015-03-04 | Sep           | CDE    |
| 2014 | 2014-03-03 | Sep           | CDE    |
+------+------------+---------------+--------+

and AllProducts
+-----------------+---------------+--------+
|      Date       | DeliveryMonth | Symbol |
+-----------------+---------------+--------+
| 2016-01-07      | June          | ABC    |
| 2016-01-08      | June          | ABC    |
| 2016-01-09      | June          | ABC    |
| 2016-01-10      | June          | ABC    |
| 2015-01-01      | June          | ABC    |
| 2015-01-02      | June          | ABC    |
| 2015-01-03      | June          | ABC    |
| 2014-01-05      | June          | ABC  |
+-----------------+---------------+--------+

Results I am looking for the Updated Table @Temdate1:
+------+------------+---------------+--------+
| Year | Entry_Date | DeliveryMonth | Symbol |
+------+------------+---------------+--------+
| 2016 | 2016-01-07 | June          | ABC    |
| 2015 | 2015-01-01 | June          | ABC    |
| 2014 | 2014-01-05 | June          | ABC    |
| 2016 | 2016-03-05 | Sep           | CDE    |
| 2015 | 2015-03-04 | Sep           | CDE    |
| 2014 | 2014-03-03 | Sep           | CDE    |
+------+------------+---------------+--------+

I have this query to find the smallest (earliest) date for a given Year and a given Product. With this query how to Update Temdate1 with the earliest date when ever it doesn't have the earliest date?
SELECT 
 Year
,CASE 
     WHEN MIN([Date])<entry_date THEN MIN([Date]) 
     ELSE entry_date 
 END AS MDate 
FROM @TempDate1 a
INNER JOIN AllProducts b on a.DeliveryMonth =b.DeliveryMonth AND a.Symbol = b.Symbol
GROUP BY Year,entry_date

A:

It seems you make a typo in expected results, Or maybe was me
Update a
   set Entry_Date = case when a.Entry_Date> b.Date then b.Date else a.Entry_Date end
from  
   @Tempdate1 a
inner join 
   @AllProducts b 
   on b.Symbol = a.Symbol
   and b.DeliveryMonth = a.DeliveryMonth
   and year(b.[Date]) = a.Year

http://rextester.com/AQXR21093

