473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Select with AND OR clause

Stang02GT
1,208 Expert 1GB
I am trying to get the right syntax around a select statement. Here is what I am trying to do.


I am selecting rows from a table based on date ranges that works fine. Where i am getting stuck is there is a third field i need to include that will either have a value or if it's left blank i need to return all the rows for the date range or i need to return all the rows for the date range and with the selected PAY_CYCLE

I was trying to do it with an AND OR

This is the specific syntax I am having issues with is the and or correct to use in this case? What should i use in my OR clause?

AND (A.PAY_CYCLE = :1 OR A.PAY_CYCLE = ?)

Any help is appreciated!
Jan 4 '13 #1
4 1866
Anas Mosaad
185 128KB
Let me try to rephrase the problem:
Third field (say: f3) can either have a value or NULL.
If f3 is null, either:
- return all rows for the date range.
- OR, return all rows for the date range and with the selected PAY_CYCLE.

I'm trying to help but I see the question not clear. In the case when you return all rows for the date range, they include the ones with the selected PAY_CYCLE.

Please try to rephrase the problem to be able to help you.

Thanks
Jan 5 '13 #2
Stang02GT
1,208 Expert 1GB
Sorry for the confusion. Sometimes the hardest part is explain the issue. Your rephrase is correct.
Jan 8 '13 #3
Anas Mosaad
185 128KB
No need to be sorry. I'm not a native English speaker and I cause lots of confusions many times. May be the I'm the only one who gets confused.
Anyway, back to your issue: when should it return all the rows? and when should it return only those with a matching PAY_CYCLE?
If either of them can be returned, you can always try to return all!
Jan 8 '13 #4
Stang02GT
1,208 Expert 1GB
So right now there are three prompts that the user has they are…

From Date
To Date
Cycle

Here are the different scenarios.
1. Users what to run the query for a specific date range and want to include all of the cycles.
2. The users want to run the query for a specific date range AND for one specific cycle.

My issue is that my query currently works if the users enter both a date range and a cycle. However I cannot get the query to work if the I use just the date ranges and exclude a specific cycle.

Right now I think that my issue is around how I am joining the tables in my query. I am joining them on cycle because it is in all three of the tables I am querying from. I think because that is what I am joining on that if I exclude it from the query it is not working correctly.
Jan 9 '13 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: joy | last post by:
I am writting a procedure, i am using a table: part(empno,...,partid,..). I already know the partid, and I need to know empno so I can use it to invoke another procedure--like empb(myid). part of...
5
by: malcolm | last post by:
Example, suppose you have these 2 tables (NOTE: My example is totally different, but I'm simply trying to setup the a simpler version, so excuse the bad design; not the point here) CarsSold {...
6
by: Peter Theill | last post by:
I'm having this query: SELECT ss.subscription_id AS SubscriptionId, s.id AS ScopeId, s. AS ScopeName, s.base AS ScopeBase, dbo.iqGetShapesByScopeAsString(s.id) AS ShapesAsString FROM
8
by: Jean | last post by:
Hello all, I have the following data, that was queried and sorted to columns PROBLEM_ID and then by STATUSDATE (ascending): STATUS_ID STATUSDATE PROBLEM_ID --------- ---------- ...
2
by: Lone Wolf | last post by:
We have a recordset with the following structure id (int), mls (varchar) What we need to do is within a single sql call we need to show all records where the mls = '' and all unique records...
5
by: No bother | last post by:
I am using 5.0.26-NT on Windows 2000. I have need to use a reference in the outer from clause in a subquery in the select clause. Consider the following example: Select (select b.baitID from...
0
by: madhavi123 | last post by:
Hi All, I have to create a report in sql server 2005 and I this happens to be my first project in SQL Server. The report has to display a sum for each group and at the end display for all the...
5
by: paragpdoke | last post by:
Hello Everyone. I'm new to XSL and couldn't get something to work. Sample XML excerpt: <root> <ObjectTemplate> <NodeType1></NodeType1> <NodeType2></NodeType2> </ObjectTemplate> <Object>
1
by: dominicpouzin | last post by:
I am trying to safely pass the list of fields to select, as in: OdbcCommand odbcCommand = new OdbcCommand(); odbcCommand.CommandText = "SELECT ? FROM myTable"; odbcCommand.Parameters.Add(new...
1
by: loix | last post by:
I'm trying to Insert 300.000 rows (or thereabouts) into a table (via QMF) using the following Select clause: # Insert into table_name ( Select row1, row2, row..x from table_name2 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.