Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 844221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:15:04+00:00 2026-05-15T06:15:04+00:00

I have a database that logs when an employee has attended a course and

  • 0

I have a database that logs when an employee has attended a course and when they are next due to attend the course (courses tend to be annual).

As an example, the following employee attended course ‘1’ on 1st Jan 2010 and, as the course is annual, is due to attend next on the 1st Jan 2011. As today is 20th May 2010 the course status reads as ‘Complete’ i.e. they have done the course and do not need to do it again until next year:

EmployeeID    CourseID    AttendanceDate    DueDate     Status
123456        1           01/01/2010        01/01/2011  Complete

In terms of the DueDate I calculate this in SQL when I update the employee’s record e.g. DueDate = AttendanceDate + CourseFrequency (I pull course frequency this from a separate table).

In my web based app (asp.net mvc) I pull back this data for all employees and display it in a grid like format for HR managers to review. This allows HR to work out who needs to go on courses.

The issue I have is as follows.

Taking the example above, suppose today is 2nd Jan 2011. In this case, employee 123456 is now overdue for the course and I would like to set the Status to Incomplete so that the HR manager can see that they need to action this i.e. get employee on the course.

I could build a trigger in the database to run overnight to update the Status field for all employees based on the current date. From what I have read I would need to use cursors to loop over each row to amend the status and this is considered bad practice / inefficient or at least something to avoid if you can???

Alternatively, I could compute the Status in my C# code after I have pulled back the data from the database and before I display it on screen. The issue with this is that the Status in the database would not necessarily match what is shown on screen which just feels plain wrong to me.

Does anybody have any advice on the best practice approach to such an issue?

It helps, if I did use a cursor I doubt I would be looping over more than 1000 records at any given time. Maybe this is such small volume that using cursors is okay?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:15:05+00:00Added an answer on May 15, 2026 at 6:15 am

    Unless I’m missing something from your explanation, there’s no need for cursors at all:

    UPDATE
        dbo.YourTable
    SET
        Status = ‘Incomplete’
    WHERE
        DueDate < GETDATE()
    

    It would be preferable not to maintain the DueDate or Status for these records at all. I woudl expect to see Employee, Course, EmployeeCourse and EmployeeCourseAttendance tables, with which you could use the following:

    -- Employees that haven't attended a course 
    -- within dbo.Course.Frequency of current date
    SELECT
        ec.EmployeeID
        , ec.CourseID
        , eca.LastAttendanceDate
        , DATEADD(day, c.Frequency, eca.LastAttendanceDate) AS DueDate
    FROM
        dbo.EmployeeCourse ec
    INNER JOIN
        dbo.Course c
    LEFT OUTER JOIN
        ebo.EmployeeCourseAttendance eca
    ON  eca.EmployeeID = ec.EmployeeId
    AND eca.CourseID = ec.CourseID
    WHERE
        GETDATE() > DATEADD(day, c.Frequency, eca.LastAttendanceDate)
    
    -- Show all employees and status for each course
    SELECT
        ec.EmployeeID
        , ec.CourseID
        , eca.LastAttendanceDate
        , DATEADD(day, c.Frequency, eca.LastAttendanceDate) AS DueDate
        , CASE
            WHEN eca.LastAttendanceDate IS NULL THEN 'Has not attended'
            WHEN (GETDATE() > DATEADD(day, c.Frequency, eca.LastAttendanceDate) THEN 'Incomplete'
            WHEN (GETDATE() < DATEADD(day, c.Frequency, eca.LastAttendanceDate) THEN 'Complete'
          END AS Status
    FROM
        dbo.EmployeeCourse ec
    INNER JOIN
        dbo.Course c
    LEFT OUTER JOIN
        ebo.EmployeeCourseAttendance eca
    ON  eca.EmployeeID = ec.EmployeeId
    AND eca.CourseID = ec.CourseID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table in a SQL Server 2005 database that logs purchases like
We have a database that has configuration data in. When the applications are run
I have a database that contains user details including sensitive data. They're not as
I have a database that contains a date and we are using the MaskedEditExtender
I have a database that I would like class files generated from, and also
I have a database that many different client applications (a smattering of web services,
I have a database that contains a table that looks a bit like this:
I have a database that i'm dealing with which is updated every few hours
I have a database that is stuck in single-user mode. I kill the process
We have a database that persist our metadata and data. Our metadata is produced

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.