当前位置: 代码迷 >> Sql Server >> “where is not null” 话语为什么不起作用?
  详细解决方案

“where is not null” 话语为什么不起作用?

热度:48   发布时间:2016-04-24 09:00:27.0
“where is not null” 语句为什么不起作用???
 select  top 2000     BuildingNo, rt.StdCode as Meterusetype, brbhth.LineType,UseType,DADay,DAHour,SumQty,Lable  
   from      BuildingReportByHourTypeH  brbhth 

 left join  (select CodeId,StdCode from  CodeDetail where  CodeGroupNo='MeterUseType')  as  rt  on   brbhth.LineType=rt.CodeId
  where   brbhth.LineType is not null

这里的brbhth.LineType is not null  没起作用啊,查出来的结果集还有为nul来的,怎么回事???
 

 and Lable=0  and  UseType in  ('EM','WM')  and      BuildingNo  in  
  ( select BuildingNo from Building where  UploadFlag=0)     
and  brbhth.DADay>'20140000'  and   brbhth.LineType!='All'  and  brbhth.LineType!='*' 
    order  by  DADay  asc,DAHour asc



------解决思路----------------------
你那个貌似是字符串"NULL",貌似不是空值NULL
你可以试着加上条件 AND Brbhth.LineType<>'NULL'
------解决思路----------------------
改成

isnull(brbhth.LineType,'') <> '' 

------解决思路----------------------
是不是以前就存的'NULL'字符串,不是真NULL
------解决思路----------------------
很明显,你的 LineTYpe 中的 NULL ,不是 NULL 而是 "NULL";
------解决思路----------------------
NULL的字段背景色是黄色的,比如你截图中linetype的前一个字段,你问的linetype字段存的是字符串不是NULL
------解决思路----------------------
where的时候 IsNULL转化下
  相关解决方案