473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Find Duplicataes within Date Range

3
I have a table in the following format:

Expand|Select|Wrap|Line Numbers
  1. ID,EmployeeNumber,StartDate,EndDate
  2. 234332,205,2/1/2007,7/1/2007
  3. 239053,203,2/1/2007,NULL
  4. 295382,204,4/29/2007,NULL
  5. 288392,205,6/23/2007,NULL
  6.  
All IDs are unique.
An Employee Number should be assigned to a single ID for every calendar day (e.g. Employee Number 205 should only be assigned to one given ID for any given date.).

I'd like to create a query in Access that will look for overlapping Employee Number assignments and list for me what dates they are overllaping.

For example:
ID,EmployeeNumber,StartDateOverlap,EndDateOverlap
234332,205,6/23/2007,7/1/2007
288392,205,6/23/2007,7/1/2007

Or...
Date,EmployeeNumber,ID
6/23/2007,205,234332
6/23/2007,205,288392
6/24/2007,205,234332
6/24/2007,205,288392
etc.

Is there a simple way to get a query set up for this? I'm definitely having some trouble wrapping my head around it as I'm having trouble figuring out how to work with the date ranges to look for dupes.

-J
Aug 5 '07 #1
4 1790
ADezii
8,834 Expert 8TB
I have a table in the following format:

Expand|Select|Wrap|Line Numbers
  1. ID,EmployeeNumber,StartDate,EndDate
  2. 234332,205,2/1/2007,7/1/2007
  3. 239053,203,2/1/2007,NULL
  4. 295382,204,4/29/2007,NULL
  5. 288392,205,6/23/2007,NULL
  6.  
All IDs are unique.
An Employee Number should be assigned to a single ID for every calendar day (e.g. Employee Number 205 should only be assigned to one given ID for any given date.).

I'd like to create a query in Access that will look for overlapping Employee Number assignments and list for me what dates they are overllaping.

For example:
ID,EmployeeNumber,StartDateOverlap,EndDateOverlap
234332,205,6/23/2007,7/1/2007
288392,205,6/23/2007,7/1/2007

Or...
Date,EmployeeNumber,ID
6/23/2007,205,234332
6/23/2007,205,288392
6/24/2007,205,234332
6/24/2007,205,288392
etc.

Is there a simple way to get a query set up for this? I'm definitely having some trouble wrapping my head around it as I'm having trouble figuring out how to work with the date ranges to look for dupes.

-J
This will be a good start for you:
Expand|Select|Wrap|Line Numbers
  1. SELECT EmployeeNumber, ID, StartDate, EndDate
  2. FROM tblAssignments
  3. WHERE EmployeeNumber In (SELECT [EmployeeNumber] FROM [tblAssignments] As Tmp GROUP BY [EmployeeNumber] HAVING Count(*)>1 )
  4. ORDER BY tblAssignments.EmployeeNumber;
  5.  
Aug 5 '07 #2
JulioL
3
I have a table in the following format:

Expand|Select|Wrap|Line Numbers
  1. ID,EmployeeNumber,StartDate,EndDate
  2. 234332,205,2/1/2007,7/1/2007
  3. 239053,203,2/1/2007,NULL
  4. 295382,204,4/29/2007,NULL
  5. 288392,205,6/23/2007,NULL
  6.  
Let me clarify the example a little bit. Here's a bit more data that may be found in the table:

Expand|Select|Wrap|Line Numbers
  1. ID,EmployeeNumber,StartDate,EndDate
  2. 234332,205,2/1/2007,7/1/2007
  3. 239053,203,2/1/2007,NULL
  4. 295382,204,4/29/2007,NULL
  5. 288392,205,6/23/2007,NULL
  6. 289553,206,2/1/2007,7/1/2007
  7. 928602,206,7/2/2007,NULL
  8.  
You'll notice two EmployeeNumber values are dupes, 205 and 206. In the case of EmployeeNumber 206, you have no overlap in the date period. 206 was used from 2/1 to 7/1 and reused for 7/2 forward.

I'd like to catch the cases where there's an overlap in EmployeeNumbers based on date range. For example, 205 in this example shows to be used both by 234332 and 288392 from 6/23 to 7/1. I don't want to catch those cases where there's no date overlap (such as in EmployeeNumber 206).
Aug 6 '07 #3
ADezii
8,834 Expert 8TB
Let me clarify the example a little bit. Here's a bit more data that may be found in the table:

Expand|Select|Wrap|Line Numbers
  1. ID,EmployeeNumber,StartDate,EndDate
  2. 234332,205,2/1/2007,7/1/2007
  3. 239053,203,2/1/2007,NULL
  4. 295382,204,4/29/2007,NULL
  5. 288392,205,6/23/2007,NULL
  6. 289553,206,2/1/2007,7/1/2007
  7. 928602,206,7/2/2007,NULL
  8.  
You'll notice two EmployeeNumber values are dupes, 205 and 206. In the case of EmployeeNumber 206, you have no overlap in the date period. 206 was used from 2/1 to 7/1 and reused for 7/2 forward.

I'd like to catch the cases where there's an overlap in EmployeeNumbers based on date range. For example, 205 in this example shows to be used both by 234332 and 288392 from 6/23 to 7/1. I don't want to catch those cases where there's no date overlap (such as in EmployeeNumber 206).
  1. I really do not think that this can be done via SQL, but I'll hang around and let the real SQL Experts have a look at it. There may, however, be a viable code (VBA) solution but I'll hold off on that also.
  2. 1 very important question, especially if you decide on a code alternative, is there a possibility that there can be more than 2 dupes? If there is this possibility, it adds to the complexity significantly.
Aug 6 '07 #4
JulioL
3
  1. I really do not think that this can be done via SQL, but I'll hang around and let the real SQL Experts have a look at it. There may, however, be a viable code (VBA) solution but I'll hold off on that also.
  2. 1 very important question, especially if you decide on a code alternative, is there a possibility that there can be more than 2 dupes? If there is this possibility, it adds to the complexity significantly.
I appreciate you lending a hand on this.

To answer your question, yes, there is a possibility of more than 2 dupes.

I hate dealing with mismanaged data. :(
Aug 6 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: bluelaser | last post by:
Hi there, i'm developing an asp.net page which contains 3 drop down boxes each for day, month and year. The problem i have is i need to ensure that the dates the user selects must be within a...
1
by: isetea | last post by:
Hi, I want to create a from where user can select from a date range / type in a date range to get only data from an underlying query within this range. This should overwrite the existing criteria...
0
by: mwalsh62 | last post by:
Greetings all! My first post here, and my mind is pudding at this point (any flavor you like)! I have been searching for days, and still can't figure out the proper syntax that I require. This...
5
by: jambonjamasb | last post by:
I am wanting to create a report that summarises the number of items within a date range. For example I have a FIELD called System_Change. This is a drop down COMBOBOX that uses words like unix,...
6
by: freeflyer30339 | last post by:
I have been pulling my hair out for a week on this one! In a query using Ms Access 2003, I am trying to group two columns. The third column is the date of the transaction. I would like the query to...
6
by: dschiewe | last post by:
Hello, This is my first time posting on here so I hope I don't ramble too much. I have a complex database that a co-worker and I created 2 years ago and that I have been adding to since then. The...
1
by: dlouche | last post by:
I want to get all the records from a table (no grouping) and order them first by a date range and then within that range order them by another column. For example, I have a table called Events: ID...
19
by: phill86 | last post by:
Hi I am re-posting this thread because it has become very confusing and I have got some way to solving the problem so it is a slightly different question from the initial thread. here is the...
3
by: Vinda | last post by:
Hi Bytes, Using a previous question as a base Access 2000 Inserting multiple rows based on a date range. I also wanted to insert multiple rows into a table according to a date range supplied by a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.