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 wOOdy-Soft 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
 
Try this:

Code:
UPDATE dbo.TmpMaster30_1
    SET    FirstProm = min(h.Prom) [COLOR=green]-- Note that I removed the "t." from the FirstProm field[/color]
    FROM   dbo.TmpMaster30_1 t,
           dbo.FACT_OF_PROM_ARCHIVE h  [COLOR=green]-- you also had an extra "," on this line, I'm sure that would have fouled things up as well.[/color]
    WHERE  t.PersonNo = h.PersonNo

I don't believe that SQL Server allows alias names on the variable being set.

Hope this helps,
John
 
Try Something like this:

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

-VJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top