Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
JeffS23
Posting Yak Master
212 Posts |
Posted - 2008-11-03 : 15:47:57
|
| I am trying to write an update statement based on an aggregate and it will not let me. Please find below the SQL. update ppSet ReleaseOfInformationIndicatorDate = IsNull(max(pv.visit),GETDATE())from PatientProfile ppinner join patientvisit pv on pp.PatientProfileId = pv.PatientProfileIdand this is the error message:Server: Msg 157, Level 15, State 1, Line 2An aggregate may not appear in the set list of an UPDATE statement.Can someone tell me how to get round this please?Many thanks |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-11-03 : 16:04:36
|
[code]update ppSet pp.ReleaseOfInformationIndicatorDate = COALESCE(pv.visit, GETDATE())from PatientProfile as ppLEFT join ( select PatientProfileId, max(visit) AS visit from patientvisit ) as pv on pv.PatientProfileId = pp.PatientProfileId[/code] E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|
|
|