Solved

SQL Where Clause

Posted on 2011-09-16
5
326 Views
Last Modified: 2012-05-12
I have the following Where Clause. I am getting date ranges that fall outside of my dates. I'm not sure how to format this so that I only get date ranges between the entered dates.

WHERE   [Disposition Date] BETWEEN '08/01/2010'
                           AND     '08/30/2011'
        AND CSC.DispositionCode IN ( '4', '5', '6', '11', '12', '13', '14',
                                     '15', '18' )
        OR ( CSC.DispositionCode = '3'
             AND [Indem Paid] >= '0.00'
           )
        OR ( CSC.DispositionCode = 'E'
             AND AppealFlag = 'Y'
0
Comment
Question by:mburk1968
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 6

Expert Comment

by:netjgrnaut
ID: 36548847
Check your column type on [Disposition Date].  Is it datetime or varchar?

Here's a link with some possible solutions...

http://demiliani.com/blog/archive/2006/01/19/3384.aspx
0
 
LVL 3

Expert Comment

by:hspoulsen
ID: 36548848
you have a problem with parentesis (sp?)

Put ( and ) around the stuff, so that your OR statements are isolated the correct way.

Best regards,
Henrik
0
 
LVL 3

Expert Comment

by:hspoulsen
ID: 36548856
Maybe like this:

WHERE   [Disposition Date] BETWEEN '08/01/2010'
                           AND     '08/30/2011'
AND (
       CSC.DispositionCode IN ( '4', '5', '6', '11', '12', '13', '14',
                                     '15', '18' )
        OR ( CSC.DispositionCode = '3'
             AND [Indem Paid] >= '0.00'
           )
        OR ( CSC.DispositionCode = 'E'
             AND AppealFlag = 'Y'
)
0
 
LVL 3

Expert Comment

by:hspoulsen
ID: 36548858
there is a ) missing at the end.
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 36548859
Use parentheses to cleanly identify your criteria.  For example:

WHERE [Disposition Date] BETWEEN '08/01/2010' AND '08/30/2011' AND 
    (CSC.DispositionCode IN ( '4', '5', '6', '11', '12', '13', '14', '15', '18' ) OR
    (CSC.DispositionCode = '3' AND [Indem Paid] >= '0.00') OR
    (CSC.DispositionCode = 'E' AND AppealFlag = 'Y'))

Open in new window

0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

752 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