Friday, March 9, 2012

Sargable Rewrite

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 droptable.com
http://www.droptable.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 droptable.comhttp://www.droptable.com/Uwe/Forums.aspx/sql-server/200702/1
WHERE cr.CreatedAt < DATEADD(day, @.days, @.dtmNow)

No comments:

Post a Comment