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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Update query based on latestdate condition

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2007-06-03 : 20:38:48
I have the following query: last_updated date i want to is the latestdate(max date), i may have 20 records, out of that 10 records has lastupdated date 02/20/2007 and another 10 records has 03/20/07.

i want to only update the latestdate records which is 03/10/07.

******************************************************
UPDATE TAB_PPSOrders
SET
Deleted = '0',
WHERE OrderID = 1 and
Last_Updated = latestdate(Max Date)
*******************************************************

Thank you very much for the information.

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-06-03 : 23:04:23
note that you have a stray comma after your SET clause. I removed it below.

UPDATE TAB_PPSOrders
SET
Deleted = '0'
WHERE OrderID = 1 and
Last_Updated = (select max(Last_Updated) from TAB_PPSOrders)


www.elsasoft.org
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-04 : 00:41:56
Do the column last_updated contain time ?


KH

Go to Top of Page

pbguy
Constraint Violating Yak Guru

319 Posts

Posted - 2007-06-04 : 00:43:53
if you are specific to the date not the time then use like this..

dateadd(dd,datediff(dd,0,Last_Updated),0) = dateadd(dd,datediff(dd,0,(select max(Last_Updated) from TAB_PPSOrders)
),0)

--------------------------------------------------
S.Ahamed
Go to Top of Page
   

- Advertisement -