hidrau
asked on
Better way to make a query with date filter.
Hello guys,
I am working In a company where there are many queries made with this kind of date filter
SELECT * FROM TABLE
WHERE CONVERT(VARCHAR(10), DATE_ORDER, 112) = CONVERT(VARCHAR(10), GETDATE(), 112)
I am in douts that this is a bad practice, even if I have the field DATE_ORDER indexed, when the filter
is made that way, the index is put aside.
What is the better way to work with date fields and filters?
thanks
Alexandre
I am working In a company where there are many queries made with this kind of date filter
SELECT * FROM TABLE
WHERE CONVERT(VARCHAR(10), DATE_ORDER, 112) = CONVERT(VARCHAR(10), GETDATE(), 112)
I am in douts that this is a bad practice, even if I have the field DATE_ORDER indexed, when the filter
is made that way, the index is put aside.
What is the better way to work with date fields and filters?
thanks
Alexandre
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ID: 42007195
How would it be? is it right this way?
How would it be? is it right this way?
Where CAST(DATE_ORDER AS DATE) >= cast('20170105' as date) and CAST(DATE_ORDER AS DATE) <= cast('20170210' as date)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks a lot
Open in new window
.. in other words:
Open in new window