IF
ストアドプロシージャに次のステートメントがあります。
if ((@someParam = 'C') OR (@someParam = 'I' AND @SomeOtherParam <> 2 AND @SomeOtherParam <> 4 AND @SomeOtherParam <> 5))
私の質問は@SomeOtherParam
、3回別々にチェックする代わりに、1回のショットでチェックインできますか?
IF
ストアドプロシージャに次のステートメントがあります。
if ((@someParam = 'C') OR (@someParam = 'I' AND @SomeOtherParam <> 2 AND @SomeOtherParam <> 4 AND @SomeOtherParam <> 5))
私の質問は@SomeOtherParam
、3回別々にチェックする代わりに、1回のショットでチェックインできますか?
これでうまくいくはずです:
if ((@someParam = 'C') OR (@someParam = 'I' AND @SomeOtherParam NOT IN (2,4,5)))
IN
値のリストを取得し、リストに値が見つかった場合はtrueを返します。追加NOT
とは、値が見つからない場合にtrueを返すことを意味します。
多分CASEステートメントで何か:
if case @someparam when 'C' then 1 when 'I' then @someotherparam NOT IN (2,4,5) else 0 end
試す
if (@SomeOtherParam NOT IN (2, 4, 5))
SQLには、使用できるEXISTSキーワードもあり ます。
if not EXISTS (select * from list where my_column= @someotherparam )