任何人都可以建议这里有什么问题吗?

我遇到多个语法错误。

IF (('05:00' < CAST(t.Scan_In_Prod AS TIME)) AND (CAST(t.Scan_In_Prod AS TIME) < '08:00'))
BEGIN
    (CASE WHEN (CAST(t.Scan_In_Prod as TIME) < CAST(t.Scan_Out_Prod AS TIME)) AND (CAST(t.Scan_Out_Prod as TIME) < '19:00')
             THEN 'Early Out'
          WHEN ('07:00' < CAST(t.Scan_In_Prod AS TIME)) AND (CAST(t.Scan_In_Prod AS TIME) < CAST(t.Scan_In_Prod AS TIME))
             THEN 'Late In'
     END)
END

错误如下所示:

最佳答案

否,应该使用select
我只改变

if (('05:00' < CAST(t.Scan_In_Prod as TIME)) and  (CAST(t.Scan_In_Prod as TIME) < '08:00'))
 begin
 SELECT case when (CAST(t.Scan_In_Prod as TIME) < CAST(t.Scan_Out_Prod as TIME)) and (CAST(t.Scan_Out_Prod as TIME) < '19:00')
        then 'Early Out'
          when  ('07:00' < CAST(t.Scan_In_Prod as TIME)) and (CAST(t.Scan_In_Prod as TIME) < CAST(t.Scan_In_Prod as TIME))
        then 'Late In'
 end

end

关于sql-server - SQL错误: If Else with Case When in SQL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48001403/

10-13 00:52