这是非常基本的东西,但我无法理解,并且手册没有帮助:
declare @rule int =
(select id from menu_availability_rules
where (daily_serving_start = null or
(daily_serving_start is null and null is null)) and
(daily_serving_end = null or
(daily_serving_end is null and null is null)) and
(weekly_service_off = 3 or
(weekly_service_off is null and 3 is null)) and
(one_time_service_off = null or
(one_time_service_off is null and null is null)));
print @rule;
-- syntax error here --\/
if (@rule is not null) raiseerror ('test error', 42, 42);
if @rule is not null
begin
delete from menu_availability
where menu_id = 5365 and rule_id = @rule
delete from menu_availability_rules
where (daily_serving_start = null or
(daily_serving_start is null and null is null)) and
(daily_serving_end = null or
(daily_serving_end is null and null is null)) and
(weekly_service_off = 3 or
(weekly_service_off is null and 3 is null)) and
(one_time_service_off = null or
(one_time_service_off is null and null is null))
and not exists
(select rule_id from menu_availability
where rule_id = @rule)
end
为什么是语法错误?我该怎么写?为了调试目的,我需要抛出错误,只是为了确保代码到达条件分支。
我可以替换为raiseerror
,select 1 / 0
我会得到我需要的,但为什么我不能正常做呢?