Solved

Select statement with and/or conditions

Posted on 2013-05-17
2
241 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how the fundamental information of how to create a table.

762 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

18 Experts available now in Live!

Get 1:1 Help Now