Solved

Aggregate function for DateTime variables??

Posted on 2002-06-03
4
259 Views
Last Modified: 2012-08-14
I have a table that contains a DateTime column, and another column that I want to use as the group indicator.  I haven't found a function that will select the latest or earliest of the DateTime values for each group.  Does one exist?

Thanks
0
Comment
Question by:garyz31
4 Comments
 
LVL 5

Expert Comment

by:spcmnspff
ID: 7052060
I'm not sure, but will this do what you described?

Latest Date for each group:

Select Group, Max(Date)
From Table
Group By Group


Earliest Date for each group:

Select Group, Min(Date)
From Table
Group By Group
0
 
LVL 1

Expert Comment

by:SYASSIN
ID: 7052640
you can also combine the two above...

select Group, max(date), min(date)
from Table
group by group
0
 

Accepted Solution

by:
Mogalappa Adaki earned 75 total points
ID: 7055408
suppose your datetime column is x and other columns are y,z

assing x as getdate() value in your program to get the date of the entry of record in the table.

select y,z,x from tablename order by x desc
0
 
LVL 1

Author Comment

by:garyz31
ID: 7117626
Thanks:  I got distracted from this project for quite a while.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

820 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