Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Users have multiple records. Query for specific records.

$
0
0

I posted this in the SQL Server Reporting Services forum, but somebody suggested trying here, so I am posting here as well.

I have Visual Studio 2008. I use it in creating BIDS reports that are then uploaded to my company's Learning Management System (LMS).

I am having an issue getting a complicated report put together. It is pulling together the records for several courses. The complications I am having is that some of the courses may have several records for the same person.

For example, the instructor led course may have a "Cancelled" record as well as a "Registered" or "Attended" record for the same person if they registered for one class session, but later cancelled that and registered for another. Further complicating things is that there is the possibility that somebody attended class, but then somehow were mistakenly registered in a later session. So, I can't even simply pull the latest record. The priority goes like this... It should pull either A) Their most recent "Attended" record if one exists B) Their most recent "Registered" record if an "Attended" record does not exist. C) Their most recent record if no "Attended" or "Registered" record exists at all. D) A blank if they have no record at all.

The Knowledge Check course may have multiple records for the same person because they may have taken the course a few times and failed, then finally taken the course and passed. However, here it is also possible that they may have passed the course, then mistakenly taken it again and failed, or started it again and remain in progress. For this case, it should pull either A) Their most recent "Pass" record. B) Their most recent "Fail" record if a "Pass" record does not exist. C) Their most recent status if they have not yet completed the course at all. D) A blank if they have no record at all.

The employees can be identified by EmpCode. The courses can be identified by ActivityCode. So, basically what I am trying to do is say when the same EmpCode has multiple records for the same ActivityCode, the query should pull the record based upon the above criteria. Can anybody explain how best to achieve this? I apologize if this is a bit much to ask, but I am having difficulty getting this to work.

Below is an example of one of the CTE's I have where I need it to pull only the correct record I want. Let me know if it would help if I provide any clarification as to what the fields below contain. I am thinking I may also need to include some sort of date identifier as well, so for the sake of the question, consider the date to be ActDate.

ILTCourse
AS
(
select
dimActivity.ActivityName ILTCourseName,
dimActivity.ID ActID,
dimActivity.Code ActCode,
dimUser.ID UserID,
dimRegistrationStatus.name RegistStatName

from
dimUser INNER JOIN
factAttempt ON factAttempt.UserID = dimUser.ID LEFT OUTER JOIN
dimActivity ON dimActivity.ID = factAttempt.ActivityID LEFT OUTER JOIN
dimRegistrationStatus ON dimRegistrationStatus.ID = factAttempt.RegistrationStatusID
WHERE
dimActivity.ActivityName LIKE '%GM101%'
AND
dimActivity.ActivityLabel LIKE '%ILT Course%'
)


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>