读书人

将不符合要求的数据暗藏

发布时间: 2012-12-16 12:02:32 作者: rapoo

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

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
[其他解释]
实在是多谢了!

读书人网 >SQL Server

热点推荐