Jump to content
xisto Community
Sign in to follow this  
eskimmer

Problem With Where Clause And Max Function Problem with where clause and max function

Recommended Posts

i have a column in a table which is varchar format but contains timedate type data eg. '24/7/07 05:32 PM'. I'm trying to run a query which uses a where clause to only return the rows where this column is equal to the most recent date. I've tried using the MAX() function which returns a valid result but not the most recent date.

Share this post


Link to post
Share on other sites

just keep refreshing the MAX it works for me and if that doesn't work, create a new table with this integrated into it and copy the data

Share this post


Link to post
Share on other sites

i have a column in a table which is varchar format but contains timedate type data eg. '24/7/07 05:32 PM'. I'm trying to run a query which uses a where clause to only return the rows where this column is equal to the most recent date. I've tried using the MAX() function which returns a valid result but not the most recent date.

Depends on the database you're using but most of them has a convertion function so you can convert from char to date, for example you can do in MS SQL "Select * from YourTableName where convert(char(10),DateAsVarcharInYourTable,101) = date()" or if you just need the last 10 records in you data you can also do "Select top 10 * from YourTableName order by convert(char(10),DateAsVarcharInYourTable,101) desc" in MySQL is a little bit more complicated, I can't remember the exact syntax but it will follow the same logic for the date translation, now why are you saving a date as varchar? just curious?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.