Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update statement with aggregates

Status
Not open for further replies.

andycape

Programmer
Aug 22, 2003
177
ZA
Is it possible to include aggregates in an update statement?

I want to do the following that is not being allowed :


Update dbo.TmpMaster30_1
set t.FirstProm = min(h.Prom)
from dbo.TmpMaster30_1 t,
dbo.FACT_OF_PROM_ARCHIVE h,
where t.PersonNo = h.PersonNo


 
I am not an expert but did you try....

Update dbo.TmpMaster30_1
set FirstProm = select (min(h.Prom)
from dbo.TmpMaster30_1 t,
dbo.FACT_OF_PROM_ARCHIVE h,
where t.PersonNo = h.PersonNo)


 
nicatt the way suggested is correct but will update all the rows of the table

Update dbo.TmpMaster30_1
set FirstProm = ( select min(h.Prom)
from dbo.TmpMaster30_1 t,
dbo.FACT_OF_PROM_ARCHIVE h,
where t.PersonNo = h.PersonNo
)
From dbo.FACT_OF_PROM_ARCHIVE
Where TmpMaster30_1.PersonNo =
FACT_OF_PROM_ARCHIVE.PersonNo

Hope the above is the correct solution
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top