SELECT [travel], [fro_m], [t_o], [dep], [arr], [fare], [discount], [faresleeper],
[rating], [seats], [s_no],
[booking_closed] =
CASE WHEN s1from <= @date AND s1to >= @date THEN s1Rate ELSE fare END
WHEN s2from <= @date AND s2to >= @date THEN s2Rate ELSE fare END
WHEN s3rate <= @date AND s3to >= @date THEN s3Rate ELSE fare END
FROM a1_volvo WHERE (fro_m = @fro_m) AND (t_o = @t_o)
答案 0 :(得分:2)
案例陈述不正确:
CASE WHEN s1from <= @date AND s1to >= @date THEN s1Rate
WHEN s2from <= @date AND s2to >= @date THEN s2Rate
WHEN s3rate <= @date AND s3to >= @date THEN s3Rate
else fare END
在case语句中的每一行之后你有else语句。它应该只在最后。
答案 1 :(得分:1)
答案 2 :(得分:0)
CASE WHEN s1from <= @date AND s1to >= @date THEN s1Rate
WHEN s2from <= @date AND s2to >= @date THEN s2Rate
WHEN s3rate <= @date AND s3to >= @date THEN s3Rate
ELSE fare
END
更好吗?
答案 3 :(得分:0)
这与他的代码相同,但在和之间使用。它们使用它的优点是,它更好的可读性。在进行代码审查时,您需要花费无穷无尽的时间来比较两个名称是否类型相同
CASE WHEN @date between s1from AND s1to THEN s1Rate
WHEN @date between s2from AND s2to THEN s2Rate
WHEN @date between s3rate AND s3to THEN s3Rate
ELSE fare
END