Is there a way to rewrite the following Where clause to make it Sargable?
DECLARE @.dtmNow datetime
DELCARE @.days int
WHERE DateDiff(d, cr.CreatedAt, @.dtmNow) >= @.days
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server/200702/1"cbrichards" <u3288@.uwe> wrote in message news:6d5e19f0998c9@.uwe...
> Is there a way to rewrite the following Where clause to make it Sargable?
> DECLARE @.dtmNow datetime
> DELCARE @.days int
>
> WHERE DateDiff(d, cr.CreatedAt, @.dtmNow) >= @.days
>
something like
WHERE cr.CreatedAt <= dateadd(d,-5,@.dtmNow)
David|||On Feb 5, 4:24 pm, "cbrichards" <u3288@.uwe> wrote:
> Is there a way to rewrite the following Where clause to make it Sargable?
> DECLARE @.dtmNow datetime
> DELCARE @.days int
> WHERE DateDiff(d, cr.CreatedAt, @.dtmNow) >= @.days
> --
> Message posted via SQLMonster.comhttp://www.sqlmonster.com/Uwe/Forums.aspx/sql-server/200702/1
WHERE cr.CreatedAt < DATEADD(day, @.days, @.dtmNow)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment