从查询中排除NULL时接收错误

时间:2015-05-13 14:28:55

标签: sql sql-server

我有这样的查询:

SELECT distinct [F_Exhibitor_Name],
       F_Site 
  FROM [V_ExhibitorLocation] 
 WHERE F_ExhibitionCode ='10996' is not null 
 ORDER BY F_Exhibitor_Name

但显示错误

  

关键字'is'

附近的语法不正确

2 个答案:

答案 0 :(得分:3)

您必须删除is not null,如下所示

SELECT distinct [F_Exhibitor_Name],F_Site 
FROM [V_ExhibitorLocation] 
Where F_ExhibitionCode ='10996' 
order by F_Exhibitor_Name

或使用不能为空的字段添加条件,如下所示

SELECT distinct [F_Exhibitor_Name],F_Site 
FROM [V_ExhibitorLocation] 
Where F_ExhibitionCode ='10996' 
and  [column]   is not null 
order by F_Exhibitor_Name

答案 1 :(得分:2)

以下布尔条件无论您解析它的方式都无效:

 WHERE F_ExhibitionCode ='10996' is not null 

据推测,你只想要:

 WHERE F_ExhibitionCode = '10996' 

这相当于:

 WHERE F_ExhibitionCode = '10996' AND F_ExhibitionCode IS NOT NULL