Solved

SQL Where Clause

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

747 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

12 Experts available now in Live!

Get 1:1 Help Now