+ -
当前位置:首页 → 问答吧 → 数据库表有一个表 的字段为空的怎么查询

数据库表有一个表 的字段为空的怎么查询

时间:2011-12-03

来源:互联网

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字段 有的为空 怎么把它查询出来



作者: scy123456   发布时间: 2011-12-03

SQL code
and  contract_Name is null

作者: Beirut   发布时间: 2011-12-03

引用 1 楼 beirut 的回复:

SQL code
and contract_Name is null


查询用楼上的,如果想在列中不显示NULL,可以用 isnull(contract_Name ,'')

作者: smilysoft   发布时间: 2011-12-03

contract_Name is null

作者: ssp2009   发布时间: 2011-12-03

where ... and contract_Name is null

作者: AcHerat   发布时间: 2011-12-03

不行呀 还是查不出来呀  

select 
  pn.*,
  cont.contract_Code,
  cont.contract_Name,
  u.user_Code,
  u.user_Truename,
  client.client_SHORTCUT client_Name,
  client.client_Id,
  client.client_Type,
  '' as employee_Name,
  0 as employee_Id 
  from
  Pay_Notice pn 
  left join
  con_Client_Emp cce 
  on pn.CCE_ID=cce.CCE_ID 
  left join
  client client 
  on cce.client_id=client.client_id 
  left join
  contract cont 
  on pn.contract_Id=cont.contract_id 
  left join
  [user] u 
  on pn.CUSTOMER_SERVICE_ID=u.USER_ID 
  where
  pn.receipt_Remind=0 
  and pn.customer_Service_Id=8 
  and pn.father_Pay_Notice_Id=0 
  and pn.receipt_Flag=2 
  and pn.CLIENT_AFFIRM=1 
  and pn.excel_Flag=0  

这个就能查出 字段为空白的 为什么上一个就不能呢??

作者: scy123456   发布时间: 2011-12-03

你要确认到底是不是 NULL ,有可能是 ''

作者: AcHerat   发布时间: 2011-12-03

引用 4 楼 acherat 的回复:
where ... and contract_Name is null



不行 还是查不出来的

作者: scy123456   发布时间: 2011-12-03

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

作者: qianjin036a   发布时间: 2011-12-03