如何在不使用where子句的情况下使用转化

时间:2019-06-12 03:03:03

标签: sql-server

我的问题是,如果我具有转换功能,我的代码将无法正常工作,因为我想显示所有数据,因此删除了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

0 个答案:

没有答案