0

我的表中有两列"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 

提前致谢。

4

1 回答 1

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
于 2012-10-09T13:34:22.123 回答