它是我的第一篇文章,我真的在MSSQL上生鏽,所以要溫柔:-)SQL - 使用datediff作爲查詢正在運行?
我有一個表,我正在嘗試使用datediff。我認爲這將是最簡單的,如果我發佈查詢和第一名的成績
select mh.agetime, mh.whatid
from mailhistory mh
inner join mail m
on mh.mailid=m.myid
where (mh.whatid=17 or mh.whatid=11 or mh.whatid=0) and maincontactid=287816 and mailid=276086
order by agetime
真的,maincontactid和mailid目前只是有限制的結果,而我做的查詢。
的結果如下...
AGETIME WHATID
1899-12-30 00:00:00.000 0
1899-12-30 00:48:10.000 11
1899-12-31 02:16:49.000 17
1899-12-31 06:29:08.000 11
1900-01-18 15:31:40.000 17
1900-02-11 14:56:59.000 11
我試圖讓第三列的查詢運行,這將使顯示的日期之差(天)第三列...項目爲11和17 WHATID ...之間,所以我喜歡這個結果後:
AGETIME WHATID DIFFERENCE
1899-12-30 00:00:00.000 0 NULL
1899-12-30 00:48:10.000 11 0
1899-12-31 02:16:49.000 17 1
1899-12-31 06:29:08.000 11 0
1900-01-18 15:31:40.000 17 18
1900-02-11 14:56:59.000 11 22
類似的東西...那麼,有沒有一種方法,我的查詢做轉換DATEDIFF喜歡跑步那?
非常感謝提前!
克里斯
嗨,我應該事先指定,但這需要運行在SQL Server 2000以及2005年......雖然在2005年很好地工作!抱歉! :-( – Twiss 2010-05-05 08:42:02