SQL Server Performance Forum – Threads Archive
Avoid filter by a column
Hi, I have a SP to filter/query around 30 fields from web application, and one of these fields to filter (if the user want) is Order_date (smalldatetime column). To query this column the user can choose ‘Today or last 2 days or last 3 days, last 7 days, last 15 days,..#%92 and each of these options send the parameter @Last_orders equal to number of specified days to SP. All works fine, but if the user choose none option (0 value) I want the SP not filter this field/column, I mean return all data even if that column has null values. How can I achieve this? Here is the condition:WHERE … And … And … And … And … And … And…
And Order_date <= DateAdd(day, DateDiff(day, 0, getdate()), 0) And Order_date > dateadd(day, [email protected]_orders, DateAdd(day, DateDiff(day, 0, getdate()), 0))
Thank you
Hi,<br />use Or instead of AND before ORDER_DATE<br /><br />[<img src=’/community/emoticons/emotion-1.gif’ alt=’

Hi, You mean for example thus?:
WHERE … And … And … And … And … And … And… Or (Order_date <= DateAdd(day, DateDiff(day, 0, getdate()), 0) And Order_date > dateadd(day, [email protected]_orders, DateAdd(day, DateDiff(day, 0, getdate()), 0)))
In this way the filter doesn’ t work
See if this helps you
http://www.sommarskog.se/dyn-search.html
Madhivanan Failing to plan is Planning to fail
]]>