Scripter25
asked on
True or False SQL
Check this one out for size
I am uploading a file for this in a minute as to hopefully explain this question a bit better.
You will see in the results in this excel file that a person had to take a test twice (dont Ask me what Attempted Test means) If they have Attempted a test or Failed a Test this script needs to check the Attempt_Number Column and see if was taken again and passed.
I need a script that will tell me True or False if all tests are passed
I need this answer ASAP I have a funeral to go to tomorrow.
Thanks in advance
The upload file should be up in a minute
I am uploading a file for this in a minute as to hopefully explain this question a bit better.
You will see in the results in this excel file that a person had to take a test twice (dont Ask me what Attempted Test means) If they have Attempted a test or Failed a Test this script needs to check the Attempt_Number Column and see if was taken again and passed.
I need a script that will tell me True or False if all tests are passed
I need this answer ASAP I have a funeral to go to tomorrow.
Thanks in advance
The upload file should be up in a minute
OK tell me do you have a table where all test details are mentioned, if yes then you need to following:-
Select Student_Number from Student Right Outer Join Test on Student.Test_Number = Test.Test_Number where Event_Type = 'Passed Test' group by Student_Number where Count(Test.Test_Number) = Count(Student.Test_Number)
Regards,
dduser
Select Student_Number from Student Right Outer Join Test on Student.Test_Number = Test.Test_Number where Event_Type = 'Passed Test' group by Student_Number where Count(Test.Test_Number) = Count(Student.Test_Number)
Regards,
dduser
IF EXISTS (
SELECT 1 FROM MyTestTable WHERE Student_Number = 10774 AND Event_Type = 'Attempted Test' AND Test_Number NOT IN
(SELECT Test_Number FROM MyTestTable WHERE Student_Number = 10774 AND Event_Type = 'Passed Test')
)
SELECT 'Not all passed' AS Result
ELSE
SELECT 'All passed' AS Result
SELECT 1 FROM MyTestTable WHERE Student_Number = 10774 AND Event_Type = 'Attempted Test' AND Test_Number NOT IN
(SELECT Test_Number FROM MyTestTable WHERE Student_Number = 10774 AND Event_Type = 'Passed Test')
)
SELECT 'Not all passed' AS Result
ELSE
SELECT 'All passed' AS Result
Sorry Correction:-
Select Student_Number from Student Right Outer Join Test on Student.Test_Number = Test.Test_Number where Event_Type = 'Passed Test' group by Student_Number having Count(Test.Test_Number) = Count(Student.Test_Number)
Select Student_Number from Student Right Outer Join Test on Student.Test_Number = Test.Test_Number where Event_Type = 'Passed Test' group by Student_Number having Count(Test.Test_Number) = Count(Student.Test_Number)
ASKER
Um ok maybe this will help
The script I am looking for is to go inside this stored procedure This SP is working miunus this one function.
CREATE PROCEDURE usp_Student_Report_51
@student_num varchar(32)
AS
SELECT dbo.department.department_ name,
dbo.Course_Definition.mand atory,
dbo.Employee.lastname,
dbo.Employee.firstname,
dbo.Classes.Class_Number,
(SELECT TOP 1 Class_events.Event_Type
FROM dbo.Class_Events
WHERE dbo.Class_Events.Class_Num ber = dbo.Classes.Class_Number
ORDER BY CASE WHEN dbo.Class_Events.event_typ e = 'Passed Course' THEN 1 WHEN dbo.Class_Events.event_typ e = 'Past Test' THEN 2 WHEN
dbo.Class_Events.event_typ e = 'Attempted Test' THEN 3 ELSE 4 END DESC) AS Event_Type,
CASE WHEN (dbo.Classes.Status = 'Classroom' OR
dbo.Classes.Status = 'Other') THEN Classes.Class_Start_Date WHEN dbo.classes.status = 'OPEN' THEN
(SELECT TOP 1 Class_events.Event_Date
FROM dbo.Class_Events
WHERE dbo.Class_Events.Class_Num ber = dbo.Classes.Class_Number
ORDER BY CASE WHEN dbo.Class_Events.event_typ e = 'Passed Course' THEN 1 WHEN dbo.Class_Events.event_typ e = 'Past Test' THEN 2 WHEN
dbo.Class_Events.event_typ e = 'Attempted Test' THEN 3 ELSE 4 END) END AS completion_date,
CASE WHEN dbo.Classes.Status = 'Classroom' THEN 'Web-Assisted' WHEN dbo.classes.status = 'OPEN' THEN 'Web-Based' ELSE 'All Other' END AS Type,
CASE WHEN (dbo.Classes.Status = 'Classroom' OR
dbo.Classes.Status = 'Other') THEN Classes.Class_Start_Date WHEN dbo.classes.status = 'OPEN' THEN Activity.Start_Date END AS Start_date,
dbo.Classes.teacher, dbo.Classes.Class_Start_Da te,
dbo.Classes.department_id,
dbo.Classes.teacher,
dbo.Students.Student_Numbe r,
dbo.Students.Bureau_ID,
dbo.Course_Definition.Cour se_Descrip tion,
dbo.Course_Definition.Stan dard_Hours
FROM dbo.Students
INNER JOIN
dbo.Activity ON dbo.Students.Student_Numbe r = dbo.Activity.Student_Numbe r
INNER JOIN
dbo.Employee ON dbo.Students.employee_id = dbo.Employee.employee_ID
INNER JOIN
dbo.Classes ON dbo.Activity.Class_Number = dbo.Classes.Class_Number
INNER JOIN
dbo.Course_Definition ON dbo.Course_Definition.Cour se_Def_Num ber = dbo.Classes.Course_Number
INNER JOIN
dbo.department ON dbo.Classes.department_id = dbo.department.department_ id
WHERE dbo.Students.Student_Numbe r = 108 AND dbo.Classes.deleted_class= 0
GO
I think DireOrbAnt is on the right track but I am unsure how to incorporate it into the above SP
The script I am looking for is to go inside this stored procedure This SP is working miunus this one function.
CREATE PROCEDURE usp_Student_Report_51
@student_num varchar(32)
AS
SELECT dbo.department.department_
dbo.Course_Definition.mand
dbo.Employee.lastname,
dbo.Employee.firstname,
dbo.Classes.Class_Number,
(SELECT TOP 1 Class_events.Event_Type
FROM dbo.Class_Events
WHERE dbo.Class_Events.Class_Num
ORDER BY CASE WHEN dbo.Class_Events.event_typ
dbo.Class_Events.event_typ
CASE WHEN (dbo.Classes.Status = 'Classroom' OR
dbo.Classes.Status = 'Other') THEN Classes.Class_Start_Date WHEN dbo.classes.status = 'OPEN' THEN
(SELECT TOP 1 Class_events.Event_Date
FROM dbo.Class_Events
WHERE dbo.Class_Events.Class_Num
ORDER BY CASE WHEN dbo.Class_Events.event_typ
dbo.Class_Events.event_typ
CASE WHEN dbo.Classes.Status = 'Classroom' THEN 'Web-Assisted' WHEN dbo.classes.status = 'OPEN' THEN 'Web-Based' ELSE 'All Other' END AS Type,
CASE WHEN (dbo.Classes.Status = 'Classroom' OR
dbo.Classes.Status = 'Other') THEN Classes.Class_Start_Date WHEN dbo.classes.status = 'OPEN' THEN Activity.Start_Date END AS Start_date,
dbo.Classes.teacher, dbo.Classes.Class_Start_Da
dbo.Classes.department_id,
dbo.Classes.teacher,
dbo.Students.Student_Numbe
dbo.Students.Bureau_ID,
dbo.Course_Definition.Cour
dbo.Course_Definition.Stan
FROM dbo.Students
INNER JOIN
dbo.Activity ON dbo.Students.Student_Numbe
INNER JOIN
dbo.Employee ON dbo.Students.employee_id = dbo.Employee.employee_ID
INNER JOIN
dbo.Classes ON dbo.Activity.Class_Number = dbo.Classes.Class_Number
INNER JOIN
dbo.Course_Definition ON dbo.Course_Definition.Cour
INNER JOIN
dbo.department ON dbo.Classes.department_id = dbo.department.department_
WHERE dbo.Students.Student_Numbe
GO
I think DireOrbAnt is on the right track but I am unsure how to incorporate it into the above SP
ASKER
oh and also the excel file was a small copy of what was in Class_Events table
DO NOT SUGGEST A JOIN OF ANY SORT AFTER THE FROM FOR THIS TABLE IT WILL SCREW THINGS UP
3 Days worth of work has taught me that much
DO NOT SUGGEST A JOIN OF ANY SORT AFTER THE FROM FOR THIS TABLE IT WILL SCREW THINGS UP
3 Days worth of work has taught me that much
you shouldn't have any problem joining to that table as it is....
however what appears to be missing is a table which contains details of the number of tests that a course requires....
your sql then becomes
coalesce((
select 'NOT PASSED'
from student as s
Inner Join StudentCourse as Sc
on s.studentid=sc.studentid
Inner Join CourseTests as CT
on sc.courseid=ct.courseid
Where Not Exists
(select 'Y'
from studenttestresults as str
Where s.studentid=str.studentid
and str.courseid=sc.courseid
and ct.testid = str.testid
and str.testresult = 'PASSED'
)
),'PASSED') as Result
just added to the select statement
although you could join it into the main body...
however what appears to be missing is a table which contains details of the number of tests that a course requires....
your sql then becomes
coalesce((
select 'NOT PASSED'
from student as s
Inner Join StudentCourse as Sc
on s.studentid=sc.studentid
Inner Join CourseTests as CT
on sc.courseid=ct.courseid
Where Not Exists
(select 'Y'
from studenttestresults as str
Where s.studentid=str.studentid
and str.courseid=sc.courseid
and ct.testid = str.testid
and str.testresult = 'PASSED'
)
),'PASSED') as Result
just added to the select statement
although you could join it into the main body...
ASKER
there is no table for that
You want another field with Passed or not? Then wrap my query in a CASE like:
CASE WHEN EXISTS (
SELECT 1 FROM MyTestTable WHERE Student_Number = 10774 AND Event_Type = 'Attempted Test' AND Test_Number NOT IN
(SELECT Test_Number FROM MyTestTable WHERE Student_Number = 10774 AND Event_Type = 'Passed Test')
) THEN 'Not all passed' ELSE 'All passed' END AS TestResult
CASE WHEN EXISTS (
SELECT 1 FROM MyTestTable WHERE Student_Number = 10774 AND Event_Type = 'Attempted Test' AND Test_Number NOT IN
(SELECT Test_Number FROM MyTestTable WHERE Student_Number = 10774 AND Event_Type = 'Passed Test')
) THEN 'Not all passed' ELSE 'All passed' END AS TestResult
where did you get the link:
https://filedb.experts-exchange.com/incoming/ee-stuff/830-mydbResults.zip
it became:
http://www.ee-stuff.com/accessLogin.php?returnURL=%2FExpert%2FUpload%2FgetFile.php%3Ffid%3D830
it is asking for my EE login - not good
https://filedb.experts-exchange.com/incoming/ee-stuff/830-mydbResults.zip
it became:
http://www.ee-stuff.com/accessLogin.php?returnURL=%2FExpert%2FUpload%2FgetFile.php%3Ffid%3D830
it is asking for my EE login - not good
ASKER
Sorry for taking so long to get back to everyone on this but DireOrbAnt this is the error I get when I try to add your script
Server: Msg 156, Level 15, State 1, Line 34
Incorrect syntax near the keyword 'CASE'.
Server: Msg 156, Level 15, State 1, Line 37
Incorrect syntax near the keyword 'THEN'.
Server: Msg 156, Level 15, State 1, Line 34
Incorrect syntax near the keyword 'CASE'.
Server: Msg 156, Level 15, State 1, Line 37
Incorrect syntax near the keyword 'THEN'.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry for the long time it took for me to accept this I have been getting extremely busy
Thank you
Thank you
Not a problem :)
ASKER
https://filedb.experts-exchange.com/incoming/ee-stuff/830-mydbResults.zip