Conditional where
Hi,
I have a below query.In last condition (ie. AND sb.timezone in )i have to pass 0 when sa.timezone_subject is null
elae i have to pass (1,2).
for ex if sa.timezone_subject is null then
the last condition should be
AND sb.timezone in(0)
else sb.timezone in(1,2)
query
select sa.timezone_subject,sb.*
from subject_availability sa,SUBJECT_BOUNDARIES sb
where sa.year= sb.year
and sa.month = sb.month
and sa.subject =sb.subject
and sa.subject_option=sb.subject_option
and sa.lvl = sb.lvl
and sa.YEAR = 2011
AND sa.MONTH = 'MAY'
AND sa.SUBJECT = 'BIOLOGY'
AND sa.SUBJECT_OPTION = 'BIOLOGY'
AND sa.LVL = 'HL'
AND sa.language = 'ENGLISH'
AND sb.timezone in()and i have tried using case but it does't worked out please advice
HI,
select sa.timezone_subject,sb.*
from subject_availability sa,SUBJECT_BOUNDARIES sb
where sa.year= sb.year
and sa.month = sb.month
and sa.subject =sb.subject
and sa.subject_option=sb.subject_option
and sa.lvl = sb.lvl
and sa.YEAR = 2011
AND sa.MONTH = 'MAY'
AND sa.SUBJECT = 'BIOLOGY'
AND sa.SUBJECT_OPTION = 'BIOLOGY'
AND sa.LVL = 'HL'
AND sa.language = 'ENGLISH'
AND ( sa.timezone_subject is null AND sb.timezone in(1)
OR sb.timezone in(2,3)
{code}
Regards.
Al
Similar Messages
-
Conditional where clauses in database adapter
I am trying to write a query in a database adapter that allows for conditional where clauses. Specifically, I want to include or not include a where clause (and clause) if an input variable is empty or not. Can a prepared statement with lexical parameters be used in a database adapter? Or is there another way to do this?
Thanks in advance.I am afraid that you can only bind parameters to the SQL, you can't bind the SQL itself to the SQL. We do have QueryByExample support, where based on what fields are set in an example object, it will construct a different SQL select.
If you pass in
<Address>
<street/>
<city>
<state>CA</state>
</Address>
it will return all addresses in California. If you pass in:
<Address>
<street/>
<city>Los Angeles</city>
<state/>
</Address>
it will return all addresses in Los Angeles.
Thanks
Steve -
Hi,
I've got query with condition
WHERE TRUNC (data_operac) >= to_date(:1, 'YYYY-MM-DD') there is index b-tree on data_operac but cant be used (because of trunc) .
Is there any way I can rewrite that condition to make index usage possible ?
Regards.
GregLike this?
WHERE data_operac >= to_date(:1, 'YYYY-MM-DD')because following is always true
data_operac >= TRUNC (data_operac) -
Plain SQL Conditional WHERE Clause with two sub-selects
Hi SQL Experts,
I need a bit quick of help with a query.
This is a "select" statement for an OBI repository phyiscal table source object.
So I cant put PL/SQL or Stored Procedures in it. I just need
to have two different conditions/selects depending on the user role (this information comes
from the session).
The above, does not work:
--------------ORA00905. 00000 - "missing keyword"
SELECT OFFICENO FROM orgunit
WHERE
CASE WHEN 'SESSION_VARIABLE' LIKE '%globalmanager%' THEN
ASSIGNEDOFFICES =
SELECT DISTINCT ASSIGNEDOFFICES
FROM USERSTABLE INNER JOIN orgunit ON
orgunit.OFFICEKEY = USERSTABLE.OFFICEKEY
WHERE USERSTABLE.USERNAME ='VALUEOF(NQ_SESSION.USER)'
ELSE
OFFICENO =
SELECT DISTINCT OFFICENO FROM USERSTABLE
INNER JOIN orgunit ON
orgunit.OFFICEKEY = USERSTABLE.OFFICEKEY
WHERE USERSTABLE.USERNAME ='VALUEOF(NQ_SESSION.USER)'
END;
Can anyone help?Hi,
I can't tell what you want to do just by looking at code that doesn't do it. Maybe:
SELECT officeno
FROM orgunit
WHERE ( session_variable LIKE '%globalmanager%'
AND assignedofficies IN
SELECT assignedoffices
FROM usertable u1
JOIN orgunit o1 ON o1.officekey = u1.officekey
WHERE u1.username = 'VALUEOF(NQ_SESSION.USER)'
OR ( NVL ( session_variable
) NOT LIKE '%globalmanager%'
AND officeno IN
SELECT officeno
FROM usertable u2
JOIN orgunit o2 ON o2.officekey = u2.officekey
WHERE u2.username = 'VALUEOF(NQ_SESSION.USER)'
There might be some simpler and more efficient way, depending on your tables and your reuirements.
The condition u2.username = 'VALUEOF(NQ_SESSION.USER)' is almost certainly not what you really want.
Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002#9362002 -
Conditional where, or PL/SQL block as source for an interactive report?
I have this situation: The main screen of my application shows a list of documents. For now, there has to be a quick "security" built in, so administrators can see all documents, but other users can only see the documents they created (login of creator is stored in the documents table). In the future we'll probably use VPD's to enforce some rules, but for now we need a quick solution.
So i stored the administrators in a seperate table. Now i want the interactive report on the main page act as follows:
- If an admin is logged in, it has to have this query: select field 1, field 2, field 3 from documents
- For all other users: select field 1, field 2, field 3 from documents where creator = :app_user
Is this possible in one interactive report? I could make two reports with the different queries and make them conditional according to who is logged in, but this gives me two interactive reports to maintain. Is it possible to use a PL/SQL block as source for the report? I tried, but I get syntax errors. Is it possible to make the where clause conditional on some way?Hi,
Install Demonstration application to your workspace:
Home>Create Application and select Demonstration Application.
Check page 1 interactive report. That should give idea how you do it.
Br, Jari -
How create a conditional "where"?
Hi,
I have a form where I put some values and after they are used to do a query when the user click on button "submit". Maybe the user write just one or two fields from many and these fields I want to use on a where clause. So, in the 'where' clause should have just the items who was completed by user and will be used the condition 'AND' not 'OR'. Can someone help me?
Thanks, sorry my English, but I from Brazil and I speak a lot of this.Felipe,
Read this thread:
How to retrieve 2 values from a table in a LOV
and have a look in my Demo Application:
http://htmldb.oracle.com/pls/otn/f?p=31517:1
Denes Kubicek
http://deneskubicek.blogspot.com/
http://www.opal-consulting.de/training
http://htmldb.oracle.com/pls/otn/f?p=31517:1
------------------------------------------------------------------- -
Good afternoon,
I have the following issue,
I have that do a LOOP to a table Internal, ie.
Loop at it_tabla where lgart = '0100' or lgart = '0200' or lgart = '0300' or lgart = '0400' or lgart = '0500' or lgart = '0600' or lgart = '0700' or lgart = '0800' .
Endloop.
The question is, Is there any way , in the which not have that do many or in the sentence LOOP?
Kind regards.I think Rob means that it will go through the table once.
It's true for Standard tables. But as it says in the help on the WHERE clause.
While with standard tables all rows of the internal table are checked for the logical expression of the WHERE- addition, with sorted tables and hash tables (as of Release 7.0) you can achieve optimized access by checking that at least the beginning part of the table key in sorted tables and the entire table key in hash tables is equal in the logical expression through queries linked with AND. Optimization also takes effect if the logical expression contains other queries linked with AND with arbitrary operators
In this case though, the queries are linked with OR - so you still get all rows checked!
Now, if it_tabla is a sorted table with key lgart, then you could do the following:
PERFORM read_the_table USING: '0100', '0200',...
FORM read_the_table USING i_lgart TYPE ...
data: l_tabix TYPE sytabix.
READ TABLE it_table WITH TABLE KEY lgart =i_lgart TRANSPORTING NO FIELDS.
l_tabix = sy-tabix.
LOOP AT it_table FROM l_tabix INTO ls_wa.
IF ls_wa-lgart NE i_lgart.
EXIT.
ENDIF.
" Do stuff
ENDLOOP.
ENDFORM.
matt -
Modify Function and Conditional Where
I am a newbie to the Oracle world. I am working on an Oracle 8.1 system. I have experience with Microsoft SQL Server.
I have two issues that are related to Oracle, many that are not.
- first how do I go about altering a function that is currently in the database, I would like to pull the contents into an editor so that I can see how it is currently working
- second, i have a parameter that is being passed into the function above, it usually holds a value but now the developers would like to be able to pass a % meaning don't use the criteria. Is it possible to modify the function to use the parameter in the where clause if it doesn't equal %, but don't include it if it does
Thank you for assisting me while I travel in the darkThis is one way:
AND ( SEWN.STYLE.BUSINESS_UNIT_ID=SEWN.STYL_COLO_IDENTIFIER.BUSINESS_UNIT_ID
and SEWN.STYLE.STYLE_ID=SEWN.STYL_COLO_IDENTIFIER.STYLE_ID )
AND ( SEWN.LABEL.BUSINESS_UNIT_ID = BusinessUnitId
AND SEWN.STYLE.STYLE_ID >= DECODE(FromStyleID, '%', SEWN.STYLE.STYLE_ID, FromStyleID)
AND SEWN.STYLE.STYLE_ID <= DECODE(ToStyleID, '%', SEWN.STYLE.STYLE_ID, FromStyleID));[pr]
John -
Conditional WHERE clause for APEX
Dear SQL gurus,
I know that there's a APEX forum, but I think that there maybe an sql based solution for this...
What I have is a query like this:
SELECT COMMENT_ORIG, COMMENT_CHARGING
FROM CL_INVENTORY_OPEN_OUT
WHERE INCIDENTAL_FK=:P13_INCIDENTAL_FK where :P13_INCIDENTAL_FK is a field in the Web Based GUI...
What I need is to change the WHERE clause to something like this
WHERE
DECODE(:P13_INCIDENTAL_FK, NULL, 1=1, INCIDENTAL_FK=:P13_INCIDENTAL_FK)so to say:
if the : P13_INCIDENTAL_FK is null, then let the clause be 1=1, otherwise let it be NCIDENTAL_FK=:P13_INCIDENTAL_FK.
Is there a way to do this inside a sql statement?
Best Regards and THX
JohannSELECT COMMENT_ORIG, COMMENT_CHARGING
FROM CL_INVENTORY_OPEN_OUT
WHERE INCIDENTAL_FK=:P13_INCIDENTAL_FKDo not know how you are using the query, but you might try something like this
BEGIN
CASE :P13_INCIDENTAL_FK
WHEN NULL THEN
SELECT COMMENT_ORIG, COMMENT_CHARGING
FROM CL_INVENTORY_OPEN_OUT
ELSE
SELECT COMMENT_ORIG, COMMENT_CHARGING
FROM CL_INVENTORY_OPEN_OUT
WHERE INCIDENTAL_FK=:P13_INCIDENTAL_FK
END CASE;
END;Edited by: ajallen on May 7, 2010 6:44 AM -
Is this conditional WHERE clause possible?
Let's say at the beginning of a stored procedure I do this: DECLARE @hasActualHours BIT
I'll then employ logic to set this local variable to either 0 or 1.
I'm interested to know if I can then use it to either include or exclude entire "AND..." clauses within my WHERE clause?
For example:
SELECT ...
FROM ...
WHERE
Clause 1... AND
Clause 2... AND
Now, I have a Clause 3 but I
only want to include it if @hasActualHours = 1.
Is it possible to do something like that in T-SQL?
Robert>> Let's say at the beginning of a stored procedure I do this: DECLARE @hasActualHours BIT
I'll then employ logic to set this local variable to either 0 or 1.
I'm interested to know if I can then use it to either include or exclude entire "AND..." clauses within my WHERE clause? <<
No, no, no, no! Your whole approach is totally wrong. Not a little wrong, but totally wrong. You just heard that from someone who helped write the SQL Standards, has 1200+ articles and 10 books on this topic. Please listen.
SQL is a declarative language, not a procedural flow control language. Declarative languages have no flow to control; there is no IF-THEN-ELSE, no loops.
SELECT ...
FROM …
WHERE Clause 1...
AND Clause 2...
AND <expression for actual hour count> > 0.00;
>> Is it possible to do something like that in T-SQL? <<
Sure, we can kludge it! But first post a statement for your boss to see that you do not care about maintaining code, performance and professionalism. This would be bad for your career; like saying you eat babies on a parenting forum :) That is what the other
replies are!
right now, you are the kid on a baseball diamond asking by which end do you hold the umpire. You are not thinking in SQL yet. My rule of thumb is you need a full year of SQL with a good mentor (read that last phrase again). It is a different mindset.
I wrote a book, THINKING IN SETS, to help with the change. See if that helps.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
Interactive report - conditional where clause
Hello,
i have an interactive report like
SELECT a.id, a.my_column
FROM my_table a
WHERE a.id = 12
Now, when the user select a assigned value, the where clause don't be execute, also like this (without where)
SELECT a.id, a.my_column
FROM my_table a
The User is not allowed to see this column, also i can not use the filter-function of the interactive report.
Any Idea how did i make?
thank's, Daniel
Message was edited by:
DaKaHi Andy, this functionalitiy is clear.
I will manipulate the region source in fact of an interaction of a user.
Now, my select shows like:
SELECT a.* FROM v_test a
WHERE (:P40_ID = -1 OR a.id = :P40_ID)
:P40_ID is a select box with return-null-value of "-1".
This is not very fast. Therefore i search a method, when user select the null-value, then the select like:
SELECT a.* FROM v_test a;
and when user select another value then:
SELECT a.* FROM v_test a
WHERE a.id = :P40_ID;
All this without the "filter"-functionality of the IR!
Any idea?
Sorry for this misunderstood.
Daniel. -
Condition where finally block doesn't get executed?
one condition when finally doesn't get executed?
kajbj wrote:
That is why i am asking basic question which is most important.Didn't my answer help? Do also note that sabre gave a subtle hint in his reply.Well, here is another, not so subtle hint that the OP might grasp.
@OP read the following line very carefully
As long as the program continues to run, the finally block will always be executed. -
Adding WHERE condition in "Calculations" tab of SSAS Cube Designer
HI,
I am using SSAS 2012 version to develop SSAS cube
and need help on following scenario :
In the BIDS designer, on the Calculations tab:
I am creating one calculated member called [% Jobs] for which I am writing MDX expression as below :
'([Measures].[On Time jobs]/[Measures].[Total Jobs])*100'
Till here all is well...
Now, How do I implement here WHERE condition ?
For ex., in my fact table I have a column Line_Number
I want to implement above MDX expression such that it only considers Line_Number=1
while doing the above calculation.
Hope it is clear.
Thanks...I tried with below method :
While keeping the expression as it is :
'([Measures].[On Time jobs]/[Measures].[Total Jobs])*100'
What I did was in the partition tab, i choose option "Query binding" (instead of Table binding) and over there I mentioned the condition
WHERE Line_Number=1
So it should do the calculations only for the first line.
Is this approach also correct ?
Thanks -
I have more than 100 tables and each table have 2 fields CompanyID And LocationNo.
for example there is a table like Sales which is containing details about tax invoices. in this table invoice number can be duplicate with CompanyID and Location number.
CompID LocNo InvoiceNo
1 1 1
1 1 2
1 2 1
2 1 1
1 1 3
I want to get all invoice data where CompanyID is 1 and LocationNo also 1.
I know i can do this with simple where condition Where CompanyID=1 AND LocationNo=1. but there are more than 100 tables which are containing same fields and also i want to get only those data where CompanyID=1 AND LocationNo=1. so i cannot put where condition
everywhere in the whole project to get specified data only.
Is there any whay to create any datasource or ODBC connection that will help me to get data from only specified criteria.
More Information
I want to do something like Tally ODBC Server which is creates temporary ODCB server to retrive data from the tally database. This server retrieves only those data which transaction date is selected in Tally Software.Thanks Satheesh for your reply.
Your idea is good.But, CompanyID and LocationNo can be different on differnt place. So, i cannot fix it with 1 or any other value.
if any way to pass both parameter into sql connection. So, when i execute only select query without where condition it will returns only specified data.
If you have used Tally then you know it creates ODBC server for its custom database. We can retrieve data into excel using TallyODBC_9000 connection.
This connection retrieves only those data which transaction date is selected in tally software.
I want to do something like this. -
Hi, I'm building a procedure with 4 parameters το pass in input and I ask if it's possible to build a select inside the procedure with a dynamic where condition.
The query with 2 conditions is the following:
SELECT count(incident_number) FROM cs.cs_incidents_all_b
1st condition
WHERE (TO_DATE(incident_attribute_6,'dd-mm-yyyy hh24:mi') BETWEEN TO_DATE(p_create_date_ll,'dd-mm-yyyy hh24:mi') AND TO_DATE(p_create_date_ul,'dd-mm-yyyy hh24:mi'))
2nd condition
AND external_attribute_4 BETWEEN p_resolv_time_ll AND p_resolv_time_ul;
The first condition has to be always valid, but the second one, depending on the parameters has to be satisfied or not.
The first 2 parameters (p_create_date_ll and p_create_date_ul) are always written as a string (so the first condition always works).
The second pair of paramenters (p_resolv_time_ll and p_resolv_time_ul) can be written as numbers (from a form), or written both as '*'
So, If the parameters p_resolv_time_ll and p_resolv_time_ul are numbers, I should retrieve a small set of data (all the 2 where condition have to work),
while if they are both '*' ONLY the first condition has to work. Practically, in this last case the 2nd condition is how it was commented.
Is it possible to build something that satisfy my request ?
Thanks in advance
AlexYes I know....
If I use an IF THEN ELSE statement I can write 2 different queries with 2 different where conditions....but I want to avoid this solution because I have 4 pair of these parameters which can assume differents values and depending on their values I have to use different where conditions
If I use an IF THEN ELSE statement, this means to write 16 different queries....
I already used DECODE or CASE but they not satisfy my request....
Anybody has others ideas ?
Thanks
Maybe you are looking for
-
Display not working on macbook air
So my screen stopped working several months ago... I have been waiting patiently for some availability to come up at any of the genius bars in London but nothing suitable has come up... The macbook powers up but the screen does nothing, just stays bl
-
#1 I already setup my credit management. It seems to work well because when I create sales and bill it, I can see that it has reflected to FD32 (credit window). My problem is, how can I make this window (see [image|http://i1104.photobucket.com/albums
-
SAP E- Recruitment and Manager BSP
Hi, When i try loging to Manager BSP encountring an error message "you dont have required authorization to use this start page". btw we are on E- Recruitment Enhancement pack 1. I have maintained the required settings. ie. reference user and a dialog
-
-
Dear Sapguru, Can we fix vendor no with particular document type in ME21N..?