2012-10-09 41 views
0

我有兩列在我的表"Edition"SQL查詢來獲取所需的輸出

現在,當我通過兩個日期,那麼輸出應該是所有的行,但在之間應該添加"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-012012-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 

在此先感謝。

回答

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