比如数据库中 一个人员表,其中只有一条性别为男的数据这个时候我以性别为女来查询,自然是查不到数据的但是这个时候我不希望出空记录,我希望能有一条记录,这条记录所有字段都是空。有没有办法做到?

解决方案 »

  1.   

    select * from 员工表 where sex=xxx
    union all
    select null,null,... from 员工表 where not exists(select 1 from 员工表 where sex=xxx)
      

  2.   

    select col1 .. from tb where sex='man'
    union all
    select null as col1.... from tb where (select count(1) from  tb where sex='man')=0
      

  3.   

    if exists(select 1 from 人员表 where 性别 = '女')
       select * from 人员表 where 性别 = '女'
    else
       select null , null , ... from 人员表
      

  4.   

    select * from 员工表 where sex='女'
    IF @@ROWCOUNT = 0
    SELECT NULL, NULL, NULL, NULL... FROM 员工表
      

  5.   

    一般都是在显示页面左做处理,Add一个DataRowsql里加一行的做法逻辑不好