[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Where statement overwrites date conditions

Posted on 2011-05-10
Medium Priority
Last Modified: 2012-05-11
I have a SP which ends with the following where statement:

WHERE closed = 1 or deleted = 1

-> this returns all the open non deleted records

WHERE convert(varchar(10),Ship_Date,101) between @Ship_Date_From and @Ship_Date_To

-> returns only records between specified dates.

I need to combine these two but when i do this it ignores date selection and gives me all the open records regardless the date selection:

WHERE closed = 1 or deleted = 1 and  convert(varchar(10),Ship_Date,101) between @Ship_Date_From and @Ship_Date_To
Question by:JessyRobinson1234
  • 2
LVL 13

Accepted Solution

Philip Pinnell earned 2000 total points
ID: 35728860

WHERE (closed = 1 or deleted = 1)  and  convert(varchar(10),Ship_Date,101) between @Ship_Date_From and @Ship_Date_To

LVL 21

Expert Comment

by:Alpesh Patel
ID: 35728946
CONVERT(varchar,getdate(),111) instead convert(varchar(10),Ship_Date,101)
LVL 13

Expert Comment

by:Philip Pinnell
ID: 35729137

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question