Solved

How to get max date

Posted on 2010-11-11
8
299 Views
Last Modified: 2012-05-10
I have a table which contains the times documents were created. There are two groups of documents, one that is created by our system automatically at 11:23 PM on a daily basis, and documents that were created by users. What I need to find out, is when the last user-created document was entered in the system in a 1 month range. For example... the date column looks like this:

date
2010-11-10 17:10
2010-11-10 17:23
2010-11-10 23:00
2010-11-11 17:24
2010-11-11 17:35
2010-11-11 23:00

My query would return the following results:
2010-11-10 17:23
2010-11-11 17:35

How can this be accomplished?
0
Comment
Question by:horalia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 34115265
I would suggest:SELECT TOP 1 DateField FROM YourTable WHERE DateField BETWEEN 'YYYY-MM-DD' AND 'YYYY-MM-DD' ORDER BY DateField DESCreplacing YYYY-MM-DD with the appropriate start and end dates for the date range you want.(I always get ASC and DESC mixed up... if that returns the OLDEST in the range, then use ASC instead of DESC at the end)
0
 

Author Comment

by:horalia
ID: 34115282
This will only return one row... I need the maximum date for a group of dates.....
0
 

Author Comment

by:horalia
ID: 34115304
I have created this query:
select convert(nvarchar(10),sentdatetime,110), max(sentdatetime)
from alg_fax (nolock)
where sentdatetime > '2010-11-01'
group by convert(nvarchar(10),sentdatetime,110)

But I get rows for 11:00 PM. How can I exclude these rows?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34115307
This is going to be interesting.
What other columns are available on the table? That differentiates between user and system?

date
2010-11-10 17:10
2010-11-10 17:23  <<< why this?
2010-11-10 23:00
2010-11-11 17:24
2010-11-11 17:35  <<< why this?
2010-11-11 23:00
2010-11-11 23:55  <<< what if there is this one?

My query would return the following results:
2010-11-10 17:23
2010-11-11 17:35

My guess is that you want the latest datetime prior to 23:00, PER day?  See 3rd << note above.
0
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 34115313
select convert(nvarchar(10),sentdatetime,110), max(sentdatetime)
from alg_fax (nolock)
where sentdatetime > '2010-11-01' and datepart(hour, sentdatetime) < 23
group by convert(nvarchar(10),sentdatetime,110)
0
 

Author Comment

by:horalia
ID: 34115316
I want the times that show before 23:00. Maybe using DATEPART?
0
 
LVL 96

Expert Comment

by:Lee W, MVP
ID: 34115402
didn't register you were looking for a grouping...

Without knowing field names, my answer could have worked for your question as quoted below.
"What I need to find out, is when the last user-created document was entered in the system in a 1 month range"
0
 

Author Comment

by:horalia
ID: 34115419
I might have chosen the wrong comment, I want to award points and accept cyberkiwi's answer.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question