473,399 Members | 3,401 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,399 software developers and data experts.

Retrieving duplicate consecutive records(How to make query for this scenario?)

Hi all

I have a table in which I save a record each time when a user checks in and checks out the

office through a time in/ time out device(this device takes thumb impression of user, thus

inserts record)


table definition is as follows:
checkInOutID (PK,int,not null)
employeeID (FK, int, not null)
isCheckIn (bit, not null)
checkInOutTime (datetime, not null)

where ischeckIn is "true" if user checks in and "false" if user checks out.

if there are alternative checkin/check out records in the table then it means that there's

no suspect entry of user. but if there are any multiple consecutive records of check in or

check out, then all those entries will be considered to be suspicious.

PLEASE HELP ME IN MAKING A QUERY OR A STORED PROCEDURE TO RETRIEVE ALL THOSE SUSPECT

ENTRIES.

I will be extremely grateful!!

Regards,
Nazish
Feb 25 '08 #1
2 2060
in order to check doubtful records

select employee_id,max(check_date_time) as max_check_time,check_type
from table
where Check_Date_Time>='2008-mon-day 00:00:00.000' and Check_Date_Time<='2008-mon-day 23:59:59.000'
group by Employee_Id,check_type
order by 1
Feb 29 '08 #2
Delerna
1,134 Expert 1GB
How about this
assuimg the table is called tblBundy
Expand|Select|Wrap|Line Numbers
  1. SELECT checkInOutID,
  2.        employeeID,
  3.        isCheckIn,
  4.        checkInOutTime,
  5.        isCheckInNext
  6. FROM
  7. (   SELECT checkInOutID,
  8.           employeeID,
  9.           isCheckIn,
  10.           checkInOutTime,
  11.           (  SELECT TOP 1 isCheckIn
  12.              FROM tblBundy b
  13.              WHERE a.EmployeeID=b.EmployeeID 
  14.                   and year(a.checkInOutTime)=year(a.checkInOutTime)
  15.                   and month(a.checkInOutTime)=month(a.checkInOutTime)
  16.                   and day(a.checkInOutTime)=day(a.checkInOutTime)
  17.             ORDER BY checkInOutTime
  18.          ) as isCheckInNext
  19.    FROM tblBundy a
  20. )
  21. WHERE isCheckIn=isCheckInNext
  22.  
Of course if there are a lot of records this could be quite slow.
To get around that perhaps you could have a stored proc that has from and to date parameters.
The storerd proc would then save the records from the main table, that are within the date range, into a table variable and run the above query using the table variable and return the suspect records in that date range.
By the way I haven't tested the above query. Its straight from my mind into this post so there may be some bugs
Feb 29 '08 #3

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

Similar topics

2
by: Jon | last post by:
can you use memo fields in a duplicate query?
2
by: Jason | last post by:
I have a table of 650,000 records associated to contracts. Some of the contracts have multiple records but each contract only has one Active Record (there might be several inactive records). ...
1
by: John M | last post by:
Hi, I have two incomplete lists of staff which combined create a full list of staff with duplicates. I wish to create a full list with no duplicates. Each member of staff has and obviously a...
2
by: P B via AccessMonster.com | last post by:
I have a list of 160,000 records with these fields: fname, lname, address, city, state, zip, dob I need to generate a list with all fields where the first initial of lname and the dob are...
2
by: lewie | last post by:
I am trying to construct a semi duplicate query. I want it to match 2 fields and check a range for the 3rd match as follows date = date, title = title, and start time between start time and end...
4
by: alltechsolutions.net | last post by:
Been at this for two days now... I have a customer database with various fields, two of which are: ContactID (an autonumber field) & ReferralID (long Integer) When a customer refers someone...
1
by: Hexman | last post by:
Hello All, What I'm trying to do is update a child record using a parent-child relation. I want to find out if it is faster than than doing multiple selects. Anyways, I've created a dataset...
1
by: sushant2009 | last post by:
Hi , I want to display empty databae table(actually table contains lot of records) to datagrid using dataset and dataadpter. After displaying i will fill new records in datagrid and i will save...
4
by: z1freeride | last post by:
I'm trying to launch my C# app from a website and send it some query parameters like so: http://www.test.com/app.application?param1=test&param2=test2 According to:...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.