首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

查询时不符合条件的显示为空,该怎么处理

2012-01-21 
查询时不符合条件的显示为空rt怎么样让select*from表where条件当表里的字段不符合条件时显示主值和一行空

查询时不符合条件的显示为空
rt
怎么样让
select   *   from   表   where   条件
当表里的字段不符合条件时显示主值和一行空格而不是什么都不显示

[解决办法]
select * from 表 where 条件

union all

select 主值, ' ', ' ', ' '…… from 表 where 主值 not in (select 主值 from 表 where 条件)
[解决办法]

select a.主值,isnull(b.辅值, ' ')
from 表 a left join 表 b on a.主值=b.主值 and b.辅值=条件
[解决办法]
select 主键,
case when 条件 then col1 else null end col1,
case when 条件 then col2 else null end col2,
...
from table
[解决办法]
create table T_200701018_1
(
aa varchar(20) primary key,
bb varchar(20)
)
insert into T_200701018_1(aa,bb) values( 'a ', 'a ')
insert into T_200701018_1(aa,bb) values( 'b ', 'b ')
insert into T_200701018_1(aa,bb) values( 'c ', 'c ')

select * from T_200701018_1

select aa,bb from T_200701018_1 where aa = 'a '
union
select aa,null bb from T_200701018_1 where aa != 'a '



[解决办法]
看联机帮助塞
[解决办法]
用case
[解决办法]
select * from 表 where 条件
union all
select 主值, ' ', ' ' from 表 where not in 条件

热点排行