Kurt Ross
asked on
performance query
what's the best way to (performance wise) or other to write this query to get all the fields that are 25 days old
select 1, 2
from table
WHERE DATEADD(DD,25,ThisDATE)>=G ETDATE()
select 1, 2
from table
WHERE DATEADD(DD,25,ThisDATE)>=G
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
-- ASSUMING YOU DON'T HAVE ANY RECORDS IN THE TABLE AFTER TODAY
-- IF YOU DO HAVE RECORDS AFTER TODAY THEN
When using date filter it's better to cast/convert datetime to date as calculating time will create performance issue for large data. Hope it helps. :)
SELECT
1, 2
FROM
TABLE
WHERE
COLUMN >= DATEADD(DD,-25,GETDATE())
-- IF YOU DO HAVE RECORDS AFTER TODAY THEN
SELECT
1, 2
FROM
TABLE
WHERE
COLUMN BETWEEN CAST(GETDATE()-25 AS DATE) AND CAST(GETDATE() AS DATE)
When using date filter it's better to cast/convert datetime to date as calculating time will create performance issue for large data. Hope it helps. :)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
also, you may consider to create index for your search field to improve performance.