Forum Discussion

togethere's avatar
togethere
Copper Contributor
Nov 19, 2024

SQL Server 2022 DateDiff D not working

Just updated an SQL server 2017 instance to 2022 and a very simple where clause using DataDiff(d) no longer works in a stored procedure.

Here is the where clause:

...AND datediff(d, A.Custfirstvisit,getdate()) < 7

Simple, but no longer working.

Tried casting as int, changing the 7 to being loaded into a declared int type var. Nope.

But, I can perform addition etc. e.g. subtract the 7 from the DateDiff(d) return valud and make the value 7 lower.

We are getting close to having to just walk away from MS tools altogether. 

Microsoft just breaking stuff that used to work now, and EASY stuff at that. Wow.

2 Replies

  • rodgerkong's avatar
    rodgerkong
    Iron Contributor

    Any weired result must be caused by unusual condition. The issue you descripted might be caused by different server or db configurations, unexpect data in table, other compatibility issues in context of the stored procedure. But not caused by datediff(d) and comparison operator.

    If you really want to resolve the problem, try to provide more information instead of complaining.

  • olafhelper's avatar
    olafhelper
    Bronze Contributor

    "Simple, but no longer working." means what in detail?

    No result, wrong result, or ...?

Resources