0

これは非常に基本的なことですが、私には理解できず、マニュアルは役に立ちません。

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

なぜ構文エラーなのですか?どうやって書くの?コードが条件分岐に到達したことを確認するためだけに、デバッグ目的でエラーをスローする必要があります。

で置き換えるだけraiseerrorselect 1 / 0、必要なものを手に入れることができますが、なぜ正常にできないのですか?

4

1 に答える 1

2

正しい名前はRAISERROR.

于 2013-03-10T16:09:28.677 に答える