I'm writing a StoredProcedure where I need to know whether there is a Resultset in the table that has been updated within the last 10 seconds. My idea was:
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
I get the following Error-Code here:
The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart.
Hope you can help me.
=======================================
Solution:
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())