Hi,following code is working one
.SELECT EmpId ,CAST(InTime AS DATE) as workingday ,EmpName,RIGHT('0' + CONVERT(varchar, FLOOR(SUM( DATEDIFF( MI, InTime, OutTime)/60.0))) , 2) + ':' + RIGHT('0' + CONVERT(varchar, SUM( DATEDIFF( MI, InTime, OutTime))%60), 2) AS [total work_hour(s)],
convert(varchar(5), max(OutTime)-MIN(InTime),108) as Emp_Intime
FROM [Baiju].[dbo].[HbaEmp]
GROUP BY EmpId , EmpName, CAST(InTime AS DATE)
I want to add a case when statement in the code.final code is as follows
SELECT EmpId ,CAST(InTime AS DATE) as workingday ,EmpName,RIGHT('0' + CONVERT(varchar, FLOOR(SUM( DATEDIFF( MI, InTime, OutTime)/60.0))) , 2) + ':' + RIGHT('0' + CONVERT(varchar, SUM( DATEDIFF( MI, InTime, OutTime))%60), 2) AS [total work_hour(s)],
convert(varchar(5), max(OutTime)-MIN(InTime),108) as Emp_Intime,dstatus=
(CASE WHEN CONVERT(TIME,intime,108)>'08:35' and CONVERT(TIME,intime,108) <'11:00' THEN 'L' WHEN CONVERT(TIME,intime,108)>'11:00' THEN 'halfday' else 'right' end )
FROM [Baiju].[dbo].[HbaEmp]
GROUP BY EmpId , EmpName, CAST(InTime AS DATE)
following error is showing
Msg 8120, Level 16, State 1, Line 3
Column 'Baiju.dbo.HbaEmp.InTime' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Msg 8120, Level 16, State 1, Line 3
Column 'Baiju.dbo.HbaEmp.InTime' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Msg 8120, Level 16, State 1, Line 3
Column 'Baiju.dbo.HbaEmp.InTime' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
how to solve this
Regards
Baiju