开发者

How do I select a column with the latest "datetime" data type?

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.


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.


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜