Solved

Select statement with and/or conditions

Posted on 2013-05-17
2
248 Views
Last Modified: 2013-05-17
I have a select statement that contains multiple (and) conditions as well as an (or) condition.
The or portion doesn't seem to work.  I was wondering if I could get another set of eyes to look at this to see what I'm doing wrong.
I basically have data in this file with the original company as one of the fields and I'm passing a parameter for the company number but I have one exception.
I want all the records that contain that company number to be selected or (if the company number in the record is not equal to the company parameter passed and the type is 'INT'

select      tfgld106.*, tfgld008.*
            from       tfgld106, tfgld008
            where      tfgld106._index1 = {:ttyp.f, :docn.f}
            and     tfgld106.fyer = :year.f      
            and      tfgld106.leac inrange :leac.f and :leac.t
            and      tfgld106.fprd inrange :prod.f and :prod.t
            and      tfgld106.catg <> tfgld.catg.opening.bal
            and      tfgld106.dele <> tcyesno.yes
            and      tfgld106.leac refers to tfgld008
            and      tfgld008.subl = 0
            and      (tfgld106.ocmp = :company.number or
                         tfgld106.ocmp <> :company.number and tfgld106.otyp = "INT")


My records would look something like this:
otyp        Leac     ocmp      fprd
AB          00005    670          4
NON       00010    670          4
INT         00015    683          4

My company parameter would be equal to 670
I would want the select statement to pull all of the records above
0
Comment
Question by:mmthomasmalone
  • 2
2 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 39176149
Probably need another set of parenthesis to set the order of execution

            and      (tfgld106.ocmp = :company.number or
                         (tfgld106.ocmp <> :company.number and tfgld106.otyp = "INT"))
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39176254
Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
I have a large data set and a SSIS package. How can I load this file in multi threading?
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.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

920 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

15 Experts available now in Live!

Get 1:1 Help Now