# What's the difference between these two "qualifiers?"

What's the difference between these two qualifiers:

datediff(d, max(t.created), getDate()) <= 45

and...

I'm thinking with the first one you have all of the rows where the t.created value falls within a range defined by the difference of today's date and whatever t.created values equals to 45 days or less.

The second clause is all of the rows that have a date that's greater than today's date minus 45 days.

Even when I attempt to explain that, I'm thinking they are fundamentally the same, but am I missing something?
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Senior DBACommented:
datediff(d, max(t.created), getDate()) <= 45

= The number of calendar days (not necessarily 24-hour days) between t.created and the current date must be <= 45.

= The date and time in txn.created must be greater than the date and time 45 days before today.

The time factor is probably the most significant difference between them.
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Database ExpertCommented:
Both are same if you consider the logic.

This <<datediff(d, max(t.created), getDate()) <= 45>> is really bad for performance as it will execute this expression for each row in the table and will lead to scanning the entire table even if you have index on the column.

This <<max(txn.created) > DATEADD(DAY, -45, GETDATE()) >> is good, since we are doing maths with the constant value and SQL will calculate the constant separately since it is not dependent on the any table.

Hope it helps !!
0
Commented:
the material difference is the logical comparison, one deals with integer comparison, the other performs datetime comparison.
The datetime comparison, can be simplified by assigning the date 45 days ago into a variable to avoid running dateadd for every row
Declare @date as datetime