2013-10-18 85 views
2

我的SQL查詢Sql Server的日期顯示動態

select BookingDate from EntBookings 
where BookingDate between '01 Jan 2013' and '03 jan 2013' 

,我想輸出

1-jan | 2-Jan | 3-Jan 
+0

這是在存儲過程中的查詢?你有沒有考慮動態查詢? 「BookingDate」的日期是否連續,這意味着兩者之間不會有日期? – unlimit

回答

0

你有日期格式錯誤的列。使用

select case when BookingDate = '2013-01-01' then BookingDate end as '1-jan', 
      when BookingDate = '2013-01-02' then BookingDate end as '2-jan', 
      when BookingDate = '2013-01-03' then BookingDate end as '3-jan' 
from EntBookings 
where BookingDate between '2013-01-01' and '2013-01-03' 
+1

這是錯誤的答案 –

+0

我希望根據過濾日期的動態列 –

+0

使用2-june這樣的文本而不是2-06-2012的文本很重要嗎? –