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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with SQL syntax

Status
Not open for further replies.

vmon

IS-IT--Management
Feb 14, 2002
74
0
0
US
I want to update a flag on all records in a table based on the MAX(DateCalc). Seems like I have something wrong. I am not sure if I should be using the WHERE EXISTS. Key to table is ID and DateCalc. Some guidance would be appreciated. Thanks, vmon

UPDATE tblDos_History
SET tblDos_History.Flag_Entry = 'M'
FROM tblDos_History WHERE EXISTS
(SELECT ID, MAX(Date_Calc) AS MaxDateCalc
FROM dbo.tblDOS_History
GROUP BY ID
HAVING MAX(Date_Calc) >= @txtPriorMonthEnd)


 
I think this is what you need (not tested by me):

UPDATE tblDos_History
SET tblDos_History.Flag_Entry = 'M'
WHERE tblDos_History.[ID] = (SELECT [ID] FROM dbo.tblDos_History WHERE MAX(Date_Calc) >= @txtPriorMonthEnd)


-SQLBill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top