;with cte as (
select distinct s.S_ID,s.Name
,(select cast(count(distinct A_Date)as float)from Attendance
where a.C_ID=C_ID ) as Total_Classes,
(select count(Pre) from Attendance where a.C_ID = C_ID
and a.S_ID = S_ID and Pre = 'True') as Attended
from Course c left outer join StudentCourse sc on c.C_ID = sc.C_ID
left outer join Student s on s.S_ID = sc.S_ID
left outer join Attendance a on a.S_ID = s.S_ID and a.C_ID = c.C_ID where c.C_ID=6)
select *,
cast(Attended*100/nullif(Total_Classes,0) as decimal(10,2)) Percentage
from cte