Solved

SQL Where Clause

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

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.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

785 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