I have two bit type columns in my sql table for the staff attendance, and the type of leave like 1 for Medical Leave or 2 for Paid Leave,the values in it are like,
FirstHalfLeave Type SecondHalfLeave Type
------------ ---- ------------- ----
0(Absent) 1 1 2
1(Present) 1 1 2
I need to sum these two fields to make it leave for a single day and I need to dislay the exact result like
Type Days
---- ------
MedicalLeave 0.5
PaidLeave 1.0
for this I tried like
select cast(
sum(
(
CAST(StaffAttendance.FirstHalfStatus as Integer) +
CAST(StaffAttendance.SecondHalfStatus as integer)
)
/ 2.0
) as float
) as TotalLeave
,case when StaffAttendance.FirstHalfLeaveType = 2 OR
StaffAttendance.SecondHalfLeaveType=2 then 'Paid Leave'
else 'Medical Leave'
end as Status
from StaffAttendance
where MONTH(StaffAttendance.date)=MONTH(GetDate())
group by StaffAttendance.FirstHalfLeaveType,StaffAttendance.SecondHalfLeaveType
but its not grouping well, I dunno how to do this, can anyone help me here, thanks in advance
1 Answer