日期:2014-05-18  浏览次数:20375 次

数据库表有一个表 的字段为空的怎么查询
select pn.pay_Notice_Id,c.client_Shortcut,con.contract_Name,pn.notice_Date,u.user_Truename,pn.father_Pay_Notice_Id,pn.receipt_Date 
from Pay_Notice pn,Con_Client_Emp cce,Client c,[User] u,Contract con 
where cce.cce_Id=pn.cce_Id and 
  cce.customer_Service_Id=8 and pn.receipt_Flag=2 
and c.client_Id=cce.client_Id and con.contract_Id=pn.contract_Id 
and u.user_Id=cce.customer_Service_Id
  and ( pn.receipt_Remind !=1 or pn.receipt_Remind is null ) 
order by pn.pay_Notice_Id desc 


这个contract_Name字段 有的为空 怎么把它查询出来





------解决方案--------------------
SQL code
and  contract_Name is null

------解决方案--------------------
探讨

SQL code
and contract_Name is null

------解决方案--------------------
contract_Name is null
------解决方案--------------------
where ... and contract_Name is null

------解决方案--------------------
你要确认到底是不是 NULL ,有可能是 ''
------解决方案--------------------
cont.contract_Name 为 NULL 或 为空串,并不影响你这句查询语句的执行,因为它不在查询条件里.
至于在查到的记录集中,contract_Name 看不到,那也许它就是空串.
你说的查不到,是这个列没有值,还是查不到记录?如果是查不到记录,那要检查查询条件,如果只是这一列查不到值,那就是它本身就是空串.
建议用
select * from contract
where contract_Name is null or contract_Name=''
检查一下你表中的数据.


------解决方案--------------------
字段名 is null
------解决方案--------------------
SQL code
where isnull(contract_Name,'')= ''