Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a time and attendance SQL 2005 database

So every time some one clocks in it adds a new entry into the table with their UserID and a DateTime entry.

I have a second table with all the users details.

On a specific day, I can run a query:

SELECT * 
FROM TASVR.dbo.Persons
WHERE
    UserID LIKE '[0-9][0-9][0-9][0-9][0-9]'
    AND UserID NOT IN 
        (SELECT UserID
        FROM TASVR.dbo.TAData
            WHERE
                (
                DateTime > '" . $strDate . " 00:00:00' 
                AND DateTime < '" . $strDate . " 12:00:00'
                ))
ORDER BY LName ASC

Which returns anyone who has not clocked in or anyone who has clocked in after 12 for the given date.

Now I want to run this query over a period of 2 weeks (excluding Sat and Sun) and it to return the days they were absent (or at least the days they were present) all in the form of something useful that I can play with in PHP.

So I need a loop with some exclusions. Any ideas?

Even if I just have a list of names of anyone that was absent over the time period, then I would just create another query in a PHP loop to pull those specific people's details for the period and work from there.

Update

I have managed to figure out how I am going to display when a person is absent over a date period using php arrays. Now if only I could work out how to get a list of UserIDs of the people that have been absent at least once in the range... For now, I have it checking against EVERY SINGLE PERSON!!! Which is time consuming to say the least.

share|improve this question
 
I'd like to refer you to crons. –  Socialz Feb 24 at 9:15
 
Do you want a list of rows like this: PersonA date1 absent, Person1 date2 Present, PersonB date1 LateEntry –  Dipendu Paul Feb 24 at 9:55
 
Well, that would be a report for the entire list of 100s of people, making it a bit long. I already have a separate report for people that arrive late (was easy to work with data that exists), I just had the bosses ask for an absent list which is a lot more complicated because I need to use data that does not exist. I want a list of people who were absent (even if it is just once) for a given date range, the rest I think I could figure out with a combination of repeat queries and php. –  Demonwolf Feb 24 at 10:03
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.