IF cast(DATEDIFF(DAY, @pd_startDate, @pd_EndDate) as smallint) > 7
PRINT 'A period larger than 7 days can be used only for Raw data.'
按预期工作 但是
IF cast(DATEDIFF(DAY, @pd_startDate, @pd_EndDate) as smallint) > 7
begin
PRINT 'A period larger than 7 days can be used only for Raw data.'
RETURN
end
没有。 即使 datediff = 7,代码也会打印
我尝试了各种方案将 datediff 转换为 int、smallint 等 没有成功
这只是我的猜测,但由于您没有在 IF 语句中使用括号,因此看起来它使用缩进来查看哪些属于 IF 语句,哪些不属于。
所以我的猜测是在第二个代码片段中,IF 语句只是空的,开始又是独立的。
您是否尝试过缩进开头和结尾,然后进一步缩进该选项卡的内容?