【问题标题】:How to use RAISEERROR statement?如何使用 RAISEERROR 语句?
【发布时间】:2013-02-25 18:56:18
【问题描述】:

这是非常基本的东西,但我看不懂,手册也没有帮助:

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

标签: tsql raiseerror


【解决方案1】:

正确的名字是RAISERROR

【讨论】:

  • 同一个命令名中的两个连续的E属于不同的词,他们可能受不了了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-17
  • 2021-02-28
  • 2012-04-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多