Solved

SQL Where Clause

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

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
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.

626 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