Where statement overwrites date conditions

Posted on 2011-05-10
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
    LVL 16

    Accepted Solution


    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
    CONVERT(varchar,getdate(),111) instead convert(varchar(10),Ship_Date,101)
    LVL 16

    Expert Comment

    by:Philip Pinnell

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
    In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now