来自 澳门威尼斯人注册网站 2019-12-29 05:22 的文章
当前位置: 澳门威尼斯人平台 > 澳门威尼斯人注册网站 > 正文

mssql sqlserver in 关键字在值为null的应用举例

转自:http://www.maomao365.com/?p=6873

摘要:

转自:http://www.maomao365.com/?p=6965  

摘要:
下文通过案例分析in 关键字在值为null的应用举例,
分析出not in关键字在null值产生的异常信息
如下所示:

下文通过举例的方式讲述sqlserver中位运算的相关知识,如下所示:
实验环境:sqlserver 2008 R2

摘要:

CREATE TABLE testA(keyId INT)
CREATE TABLE testB(keyId INT)
GO
INSERT INTO testA(keyId) VALUES (1)
INSERT INTO testA(keyId) VALUES (2)
INSERT INTO testA(keyId) VALUES (3)
GO
INSERT INTO testB(keyId) VALUES (1)
INSERT INTO testB(keyId) VALUES (2)
INSERT INTO testB(keyId) VALUES (4)
INSERT INTO testB(keyId) VALUES (NULL)
GO
 SELECT * FROM testA WHERE keyId IN (SELECT keyId FROM testB)
-----输出------
/*
keyId
1
2
*/
 SELECT * FROM testA WHERE keyId not IN (SELECT keyId FROM testB)
------无输出记录-----
/*
keyId
*/
INSERT INTO testA VALUES (NULL) ---在testA表中插入空值
SELECT * FROM testA WHERE EXISTS(
    SELECT null  FROM testB WHERE testA.keyId=testB.keyId    
)
----输出----
/*
keyId
1
2
*/
SELECT * FROM testA WHERE not  EXISTS(
    SELECT null  FROM testB WHERE testA.keyId=testB.keyId    
)
/*
keyId
3
NULL
*/
SELECT * FROM testA WHERE testA.keyId NOT in (
    SELECT testB.keyId FROM testB WHERE testB.keyId IS NOT NULL    
)

drop table testA
drop table testB

下文将分享两种将字段中null值替换为指定值的方法分享,如下所示:
实验环境:sqlserver 2008 R2

本文由澳门威尼斯人平台发布于澳门威尼斯人注册网站,转载请注明出处:mssql sqlserver in 关键字在值为null的应用举例

关键词: