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

将不符合要求的数据暗藏

2012-12-16 
将不符合要求的数据隐藏数据库:IDCD1CD2CD312012-10-12012-10-102012-10-2022012-11-12012-11-102012-10-1

将不符合要求的数据隐藏
数据库:

IDCD1CD2CD3
12012-10-12012-10-102012-10-20
22012-11-12012-11-102012-10-13
32012-12-12012-10-62012-11-14

想要得到的结果:
IDCD1CD2CD3
12012-10-12012-10-102012-10-20
22012-11-12012-10-13
32012-10-6

简单来说,就是CD1、CD2、CD3字段中,范围在2012-10-1到2012-11-1之间。一般的SELECT会全部显示出来,有没有方法可以把那些不符合这个范围之内的数据隐藏?或者用其它字符来代替?

[最优解释]
select id,
(case when cd1 between '2012-10-1' and '2012-11-1' then convert(varchar(10),cd1,120 else '' end) as cd1,
(case when cd2 between '2012-10-1' and '2012-11-1' then convert(varchar(10),cd2,120 else '' end) as cd2,
(case when cd3 between '2012-10-1' and '2012-11-1' then convert(varchar(10),cd3,120 else '' end) as cd3
from tb
如果要显示其他字符,则用这些字符代替上面的''.
[其他解释]
case when then
[其他解释]
实在是多谢了!

热点排行