Avatar of Morpheus7
Morpheus7
 asked on

Update table using MIN() Function

Hi,
I am trying to update a date field using the MIN() function. when I run the code below, I just get one date  result, instead of a result for each appropriate row in the temp table.  Any one any ideas on what I am doing wrong here. All date fields are SMALLDATETIME.

UPDATE i
SET datefst = (SELECT MIN(ar.sales_date)
                        FROM prodSales ar
                        JOIN #TCI i
                        ON i.ProdCode = ar.Prodcode
                        AND i.catl = ar.catl
                        WHERE ar.sales_date BETWEEN i.fdate AND i.End_Date)
FROM #TCI i
JOIN prodSales ar
ON i.ProdCode = ar.ProdCode
AND i.catl = ar.catl
AND i.datefst IS NULL;


Many thanks
Microsoft SQL Server 2005

Avatar of undefined
Last Comment
Morpheus7

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
bcnagel

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Vitor Montalvão

Can you explain the logic of what you trying to do?
Morpheus7

ASKER
That works Great, many thanks
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23