我已经看到了SQL同时使用!=,并<>为不相等.什么是首选语法,为什么?
我喜欢!=,因为<>让我想起Visual Basic.
定义说:
当SET ANSI_NULLS为ON时,即使column_name中存在空值,使用WHERE column_name = NULL的SELECT语句也会返回零行.使用WHERE column_name <> NULL的SELECT语句返回零行,即使column_name中存在非空值也是如此.
这是否意味着此查询中不包含空值?
SELECT Region
FROM employees
WHERE Region = @region
Run Code Online (Sandbox Code Playgroud)
或者ANSI_NULL只关注像这样的查询(其中WHERE包含特定的单词NULL)?
SELECT Region
FROM employees
WHERE Region = NULL
Run Code Online (Sandbox Code Playgroud) 在编写查询时,如果我使用<>或!=,当我的意思是"不等于"时,这是否重要?
根据下面的示例,无论是否使用<>或!=,空值似乎都不会受到影响.这是美学的吗?
declare @fruit table
(
FruitID int,
FruitName varchar(50)
)
insert into @fruit (FruitID, FruitName) Values (1, 'Apple')
insert into @fruit (FruitID, FruitName) Values (2, 'Orange')
insert into @fruit (FruitID, FruitName) Values (3, 'Pineapple')
insert into @fruit (FruitID, FruitName) Values (null, 'Not a Fruit')
select *
from @fruit
where fruitid<>2
select *
from @fruit
where fruitid!=2
Run Code Online (Sandbox Code Playgroud) 在我的查询中,其他一些开发人员使用了<> (angle brackets)什么意思?
sb.append(" AND nvl(VoidFlag, 'N') <> 'Y' ");
Run Code Online (Sandbox Code Playgroud)