Это что-то очень простой, но я не могу понять, и руководство не помогает:Как использовать инструкцию RAISEERROR?
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
, и я получу то, что мне нужно, но почему я не могу это делать нормально?
По какой-то причине команда написана как 'raiserror', а не' raiseerror'. – Guffa