我的问题是,如果我具有转换功能,我的代码将无法正常工作,因为我想显示所有数据,因此删除了where
子句,因此不需要where
子句,请帮忙我。我使用convert
函数是因为我希望将时间转换为24小时至12小时
这是错误(从字符串转换日期和/或时间时转换失败。)
我的代码如下:
Select B.LastName + ',' + B.FirstName + ',' + B.MiddleName[Name] ,A.[RecordDate],B.[EmployeeNO]
CONVERT(VARCHAR(15), MIN(IIF(ISNULL(CHARINDEX('I', isnull(A.[Entries],'1666-01-01 00:00:00 000'), 0), 1) > 0, CAST( SUBSTRING(ISNULL(A.[Entries],'2019-01-01 00:00:00 000'), LEN(ISNULL(A.[Entries],'2019-05-08 00:00:00 000')) - 5, 5) AS [TIME]), NULL)), 100) AS [TimeIn],
CONVERT(VARCHAR(15), MAX(IIF(ISNULL(CHARINDEX('O', ISNULL(A.[Entries],'1666-01-01 00:00:00 000'), 0), 1) > 0, CAST(SUBSTRING(ISNULL(A.[Entries],'2019-01-01 00:00:00 000'), LEN(ISNULL(A.[Entries],'2019-05-08 00:00:00 000')) - 5, 5) AS [TIME]), NULL)), 100) AS [TimeOut]
FROM Employees [B] inner JOIN [DTR Upload] [A] ON B.EmployeeNo = A.EmpID
GROUP by B.LastName, B.FirstName, B.MiddleName,B.[EmployeeNO], A.[recordDate]
order by A.[recordDate] asc, B.LastName + ',' + B.FirstName + ','+ B.MiddleName asc