Solved

SQL Where Clause

Posted on 2011-09-16
5
321 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
  • 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

680 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