我在寫一個StoredProcedure,我需要知道表中是否有最近10秒內更新的Resultset。 我的想法是:DATEADD函數導致溢出
SELECT @CNT = ba_sales_funnel_id FROM CRM7.BA_SALES_FUNNEL WHERE project_id = @project_id
and sale_id = @sale_id
and DATEDIFF(SECOND, updated, GETDATE()) < 10
我收到以下錯誤代碼在這裏:
DateDiff函數導致溢出。分隔兩個日期/時間實例的日期部分數量太大。嘗試使用不精確的日期部分的datediff。
希望你能幫助我。
=======================================
解決方案:
SELECT @CNT = ba_sales_funnel_id FROM CRM7.BA_SALES_FUNNEL WHERE project_id = @project_id
and sale_id = @sale_id
and DATEDIFF(YEAR, updated, GETDATE()) < 1
and DATEDIFF(MONTH, updated, GETDATE()) < 1
and DATEDIFF(DAY, updated, GETDATE()) < 1
and DATEDIFF(SECOND, updated, GETDATE()) < 10
OR
SELECT @CNT = ba_sales_funnel_id FROM CRM7.BA_SALES_FUNNEL WHERE project_id = @project_id
and sale_id = @sale_id
and updated >= DATEADD(second,-10,GETDATE())
可能重複:DATEDIFF函數導致在溢出](http://stackoverflow.com/questions/1275208/sql-server-datediff-function-resulted-in-an-overflow) – LittleBobbyTables 2014-09-29 15:06:36
Ty爲您提供幫助。問題是查詢遍歷表中的所有行並僅檢查秒。 解決方案如下: \t \t \t SELECT @CNT = ba_sales_funnel_id FROM CRM7。BA_SALES_FUNNEL WHERE PROJECT_ID = PROJECT_ID \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t和sale_id = sale_id \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t和DATEDIFF(YEAR,更新GETDATE())<1 \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t和DATEDIFF(月,更新,GETDATE())<1 \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t和DATEDIFF(DAY,更新,GETDATE())<1 \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t和DATEDIFF(SECOND,更新,GETDATE())<10 – Sney 2014-09-29 15:43:46
你看在這個答案中重複? http://stackoverflow.com/a/23638804/334849 – LittleBobbyTables 2014-09-29 15:44:39