User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 392,092 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,897 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser:
Views: 556 | Replies: 0
Reply
Join Date: Jul 2007
Posts: 1
Reputation: cyberiatech is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
cyberiatech cyberiatech is offline Offline
Newbie Poster

Question Help with odd Query

  #1  
Jul 23rd, 2007
I am trying to come up with a SQL query that will read timestamps from a table cross-referenced with the groups and individuals. What I want is results for each person on any given day with the first and last (min/max) EventTime. With the tables below, for example, an entry for Joe on 7/12/07 would need to be the first and last event on 7/12/07 within either of groups 1001 and 1003. Hopefully this makes sense.

If this is possible, and anyone could help out, I would greatly appreciate it!!!

Here's what the Events table looks like:

Id(PK) | EventTime | GroupId
===================================
1 | 1/22/2007 12:30pm | 1001
2 | 1/22/2007 2:30pm | 1001
3 | 1/23/2007 11:00am | 1002
4 | 1/23/2007 12:30pm | 1002
5 | 1/24/2007 11:00am | 1003
6 | 1/24/2007 12:30pm | 1003
7 | 1/24/2007 2:00pm | 1003


Here's what the Groups table looks like:

Id(PK) | Name
================
1001 | Accounting
1002 | HR
1003 | Sales
1004 | Marketing


Here's what the Individuals table looks like:

Id(PK) | Name | Primary | Secondary
===============================
2001 | Joe | 1003 | 1001
2002 | Bill | 1002 | 1003
2003 | Sam | 1001 | 1002
2004 | Jack | 1002 | 1003


What I need is output that would look something like this:

Date | StartTime | EndTime | Person
==================================
1/22/07 | 12:30pm | 2:30pm | Joe
1/22/07 | 12:30pm | 2:30pm | Sam
1/23/07 | 11:00am | 12:30pm | Bill
1/23/07 | 11:00am | 12:30pm | Jack
1/24/07 | 11:00am | 2:00pm | Joe
1/24/07 | 11:00am | 2:00pm | Bill
1/24/07 | 11:00am | 2:00pm | Jack
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MS SQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 12:40 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC