原来Transact-SQL可以这样写:
declare @i int;
set @i = 0;
if @i in(1,2,3,4)
select 'OK';
else
select 'oh god';
结果显示: oh god.
这说明,不用写成 if @i=1 OR @i=2 OR ... 这么蠢。
本文介绍了一种在Transact-SQL中更简洁地进行条件判断的方法,通过使用IN关键字替代多个OR操作符,提高了代码的可读性和效率。
原来Transact-SQL可以这样写:
declare @i int;
set @i = 0;
if @i in(1,2,3,4)
select 'OK';
else
select 'oh god';
结果显示: oh god.
这说明,不用写成 if @i=1 OR @i=2 OR ... 这么蠢。
9643

被折叠的 条评论
为什么被折叠?