亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

SQL查詢在兩個日期之間選擇日期

SQL查詢在兩個日期之間選擇日期

MMMHUHU 2019-07-08 16:32:11
SQL查詢在兩個日期之間選擇日期我有一個start_date和end_date..我想得到這兩個日期之間的日期列表。有人能幫我指出我查詢中的錯誤嗎。select Date,TotalAllowance  from Calculation  where EmployeeId=1   and Date between 2011/02/25 and 2011/02/27這里Date是datetime變量。
查看完整描述

3 回答

?
滄海一幻覺

TA貢獻1824條經驗 獲得超5個贊

你應該把這兩個日期放在單引號之間,比如.。

select Date, TotalAllowance from Calculation where EmployeeId = 1
             and Date between '2011/02/25' and '2011/02/27'

或可以使用

select Date, TotalAllowance from Calculation where EmployeeId = 1
             and Date >= '2011/02/25' and Date <= '2011/02/27'


查看完整回答
反對 回復 2019-07-08
?
交互式愛情

TA貢獻1712條經驗 獲得超3個贊

因為沒有指定時間段的日期時間的值為date 00:00:00.000,如果要確保得到范圍內的所有日期,則必須為結束日期提供時間,或者增加結束日期并使用<.

select Date,TotalAllowance from Calculation where EmployeeId=1 and Date between '2011/02/25' and '2011/02/27 23:59:59.999'

select Date,TotalAllowance from Calculation where EmployeeId=1 and Date >= '2011/02/25' and Date < '2011/02/28'

select Date,TotalAllowance from Calculation where EmployeeId=1 and Date >= '2011/02/25' and Date <= '2011/02/27 23:59:59.999'

不要使用以下內容,因為如果記錄的時間為00:00:00.000,則可以返回2011/02/28年度的一些記錄。

select Date,TotalAllowance from Calculation where EmployeeId=1 and Date between '2011/02/25' and '2011/02/28'


查看完整回答
反對 回復 2019-07-08
?
湖上湖

TA貢獻2003條經驗 獲得超2個贊

試試這個:

select Date,TotalAllowance from Calculation where EmployeeId=1
             and [Date] between '2011/02/25' and '2011/02/27'

日期值需要輸入為字符串。

為了確保將來對SQLServer 2008及更高版本的查詢進行校對,Date應該轉義,因為在以后的版本中它是一個保留字。

請記住,沒有時間的日期以午夜作為默認值,因此您可能沒有正確的值。


查看完整回答
反對 回復 2019-07-08
  • 3 回答
  • 0 關注
  • 3946 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號