我的表"Edition"
现在,当我传递两个日期时,输出应该是所有行,但是对于中间的所有行,应该添加"New"
作为结果。
所以,我的表包含:
id edition_date
----------- -----------------------
242 2011-01-01 00:00:00.000
243 2011-02-01 00:00:00.000
244 2011-03-01 00:00:00.000
245 2011-04-01 00:00:00.000
当我通过2012-02-01
和2012-03-31
所需的输出:
id edition_date Result
----------- ----------------------- -----------
242 2011-01-01 00:00:00.000
243 2011-02-01 00:00:00.000 New
244 2011-03-01 00:00:00.000 New
245 2011-04-01 00:00:00.000
提前致谢。
答案 0 :(得分:2)
declare @start datetime, @end datetime
select @start = convert(datetime, '2011-02-01',120),
@end = convert(datetime, '2011-03-01',120)
select *,
case when edition_date between @start and @end then 'New' end as Result
from
Edition