views:

47

answers:

2

How do I select a column with the latest "datetime" data type, in Visual Web Developer 2008, ASP.NET 3.5 ?

In the config data source dialog my WHERE options are greater than cookie, control, etc... but I would like to select where the datetime is the latest in the table.
(Select row from table where datetime is last updated....)

Thank You.

EDIT -
This will be for a specific user in the table, i.e.

Select row in table from specific current userid WHERE the row was his latest updated entry.
+1  A: 

Could you select top 1 and sort by the column descending e.g.

select top 1 ...
from MyTable
where User = @theUser
order by DateColumn desc

edit-- added in the where clause for user

that should get you a single row with the latest date from the table...i'massuming this table gets something written to it each time a user does 'something'...so you can grab what they last did...

davidsleeps
interesting, however, I have other user data in the table and am selecting based on the specific user..... So for "user 4" his data may not be at the top sorted....? It needs to be select where userid is current user and his latest column of datetime.
Greg McNulty
edited answer...
davidsleeps
great thanks..........!
Greg McNulty
+2  A: 

or you could use the MAX function like that:

SELECT * FROM myTable WHERE User='Me' AND DateColumn=(SELECT MAX(DateColumn) from myTable  WHERE User='Me')

The previous solution works perfectly though but this one can be useful for more complicated cases I think.

JSmaga