?
Solved

Select statement with and/or conditions

Posted on 2013-05-17
2
Medium Priority
?
273 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 66

Accepted Solution

by:
Jim Horn earned 2000 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 66

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Suggested Courses

839 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