Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
SELECT (SELECT DISTINCT CourseN FROM tb_course WHERE CourseN = 'CH334-' AND Sect = 'M1' AND year = 2014 AND Semester = 'FA' AND Proft = 25) AS [Course], (SELECT DISTINCT Sect FROM tb_course WHERE CourseN = 'CH334-' AND Sect = 'M1' AND year = 2014 AND Semester = 'FA' AND Proft = 25) AS [Section], (SELECT DISTINCT Skill2 FROM tb_course WHERE CourseN = 'CH334-' AND Sect = 'M1' AND year = 2014 AND Semester = 'FA' AND ProfT = 25) AS [Skill], (SELECT COUNT(Skill2CA) FROM tb_course WHERE CourseN = 'CH334-' AND Sect = 'M1' AND year = 2014 AND Semester = 'FA' AND ProfT = 25 AND Skill2CA in ('S','F')) AS [Complete], (SELECT COUNT(Skill2CA) FROM tb_course WHERE CourseN = 'CH334-' AND Sect = 'M1' AND year = 2014 AND Semester = 'FA' AND ProfT = 25) AS [Total]
Which has an output of:
Course Section Skill Complete Total CH334- M1 W 17 19
What can I do to get it to where the CourseN in the WHERE clause is unknown? I have tried placing initially in a table but the output is wrong on acomp. I would rather not have to use a temp table if possible.
UPDATE tb_temp_mycourses SET acomp = ( SELECT COUNT(Skill2CA) FROM tb_course INNER JOIN tb_temp_mycourses ON tb_course.CourseN = tb_temp_mycourses.course WHERE tb_course.CourseN = tb_temp_mycourses.course AND tb_course.Sect = tb_temp_mycourses.section AND tb_course.Skill1 = tb_temp_mycourses.skill AND year = 2014 AND Semester = 'FA' AND ProfT = 25 AND Skill2CA in ('S','F'))
select CourseN, Sect, Skill2CA, Count(CASE When Skill2CA in ('S','F') then 1 END) as Complete Count(Skill2CA) as Total From tb_course WHERE CourseN = 'CH334-' AND Sect = 'M1' AND year = 2014 AND Semester = 'FA' AND Proft = 25 group by CourseN, Sect, Skill2CA
Then, you only have to change the first predicate in the WHERE clause to return CourseN = 'Unknown'