Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help write a query

Status
Not open for further replies.

zclv05

Programmer
May 14, 2003
6
US
I need help selecting a contractor 1st log record and last log record for each day.

Contractor_Table
Co_# SSN LOG_DATETIME
100 012349991 4/27/2003 9:29:39 AM
100 012349991 4/29/2003 8:34:57 AM
100 012349991 4/30/2003 8:34:57 AM
100 012349991 4/30/2003 9:29:39 AM
100 012349991 4/30/2003 12:43:16 PM
100 012349991 4/30/2003 4:14:02 PM
110 034549991 4/30/2003 12:43:16 PM
110 034549991 4/30/2003 4:14:02 PM

The result should be:

Co_# SSN LOG_DATETIME_IN LOG_DATETIME_OUT 100 012349991 4/27/2003 9:29:39 AM
100 012349991 4/29/2003 8:34:57 AM
100 012349991 4/30/2003 8:34:57 AM 4/30/2003 4:14:02 PM
110 034549991 4/30/2003 12:43:16 PM 4/30/2003 4:14:02 PM

How can I write a query to show these result?

 
Code:
select Co_#, 
  min(log_datetime) as  LOG_DATETIME_IN  ,
  max(log_datetime) as  LOG_DATETIME_OUT 
from Contractor_Table
 group by Co_#,
   datediff('d',log_datetime,date())


 
I needed to add SSN and it gave me the results I needed.

Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top