2012-01-27 54 views
2
中獲取值

我正在使用SQL2008創建SP。在我的過程中,我想比較三個日期值並從表格中獲取兩個日期之間的數據。將兩個日期與現有日期進行比較,並從表

我從我的UI @date1@date2獲得兩個日期,我在我的表Date3列,這樣基礎上,@date1@date2Date3我想從我的表中選擇一些數據。

我該怎麼做?

回答

1

我認爲,你想要的是這樣的:

select col1, col2, col3, ... from Table 
where Date3 between @date1 and @date2 

這將讓你從Table where Date3 date is >= @date1 and <= @date2所有行。

+0

謝謝大家.. – 2012-01-27 15:39:24

+0

@IndraRamasani檢查此鏈接獲取更多信息:http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – 2012-01-27 15:54:20

2

要避免日期字段中的時間戳,您可以使用Select col1,col2... from table_name where Date(Date3) between @Date1 and @date2