gpt4 book ai didi

sql-server - SQL错误: If Else with Case When in SQL

转载 作者:行者123 更新时间:2023-12-03 08:27:13 25 4
gpt4 key购买 nike

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

我遇到多个语法错误。

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

错误如下所示:

Msg 156, Level 15, State 1, Line 25
Incorrect syntax near the keyword 'if'.

Msg 156, Level 15, State 1, Line 29
Incorrect syntax near the keyword 'case'.

Msg 156, Level 15, State 1, Line 42
Incorrect syntax near the keyword 'case'.

Msg 102, Level 15, State 1, Line 107
Incorrect syntax near 't'.

最佳答案

否,应该使用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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com