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
 General SQL Server Forums
 New to SQL Server Programming
 results of max date

Author  Topic 

gavakie
Posting Yak Master

221 Posts

Posted - 2010-03-18 : 17:01:26
So I have a table that will get updated once a month, I need to make sure that I am always choosing the results with the max(date) how would i write that?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-18 : 17:13:51
UPDATE SomeTable
...
WHERE SomeColumn = (SELECT MAX(SomeColumn) FROM SomeTable)

Is the date/time column unique in the table?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-19 : 11:42:31
I think what OP is looking at is to select the most recent data which got updated recently, so you might have to replace UPDATE with SELECT in Tara's suggestion

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

gavakie
Posting Yak Master

221 Posts

Posted - 2010-03-19 : 12:18:13
visakh16, Yes Thank you.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-19 : 12:20:00
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -