我正在写一个StoredProcedure,我需要知道表中是否有一个在过去10秒内更新过的Resultset。 我的想法是:
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())
答案 0 :(得分:1)
尝试将SQL更改为:
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())