How to use a where clause in an inner query
String approv="pend"
query = "Select Eno From EmpLeave Where Status_approval='"+approv+"' and Eno in (Select Eno from EmpLeave group by Eno having count(Eno)>1)";
bt in the result even the rows without "pend" is also displayed...
can sumone plzz tell me where should i put my where clause exactly in the above query
i do have multiple records with status approval as "pend"....
Try the below:
query = "Select Eno From EmpLeave Where Status_approval='"+approv+"'
and Eno in (Select Eno from EmpLeave group by Eno having count(distinct status_approval)>1)";
Similar Messages
-
How do you use 3 Where Clauses in a query
Hi, i am trying to figure out how to use 3 Where Clauses in a Query where 2 of the Where Clauses uses a Sub query.
Display the OrderID of all orders that where placed after all orders placed by “Bottom-Dollar Markets”.
Order the result by OrderID in ascending order.
First WHERE clause checks for OrderDate and uses a sub query with ALL keyword.
Second WHERE clause use equals and sub query.
Third WHERE clause uses equal and company name.
This is what i have so far but i am pretty confused on how to do this.
My Code for NorthWind:
Select OrderID
From Orders o
Where o.OrderID IN (Select OrderDate From Orders Where Orders.OrderID > ALL
(Select CompanyName From Customers Where CompanyName = 'Bottom-Dollar Markets'));
The book shows how to use the ALL Keyword but not in a Sub query with Multiple Where Clauses.
Select VenderName, InvoiceNumber, InvoiceTotal
FROM Invoices JOIN Vendors ON Invoices.VendorID = Vendors.VendorID
WHERE InvoiceTotal > ALL (Select InvoiceTotal From Invoices Where VendorID = 34)
ORDER BY VendorName;>Where Orders.OrderDate
> ALL (Select
CompanyName
The comparison operator (>) requires compatible data types.
DATETIME is not compatible with VARCHAR string for comparison.
Here is your homework:
SELECT orderid
FROM orders o
WHERE o.orderdate > ALL (SELECT orderdate
FROM orders
WHERE shipvia = (SELECT Max(shipvia)
FROM orders o
INNER JOIN customers c
ON c.customerid =
o.customerid
WHERE
c.companyname = 'Bottom-Dollar Markets'));
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014 -
How to use the Output clause for the updated statment
How to use the output clause for the below update stament,
DECLARE @MyTableVar table(
sname int NOT NULL)
update A set stat ='USED'
from (select top 1 * from #A
where stat='AVAILABLE' order by sno)A
Output inserted.sname
INTO @MyTableVar;
SELECT sname
FROM @MyTableVar;
Here am getting one error incorrect syntax near Output
i want to return the updated value from output clausesee
http://blogs.msdn.com/b/sqltips/archive/2005/06/13/output-clause.aspx
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
How do I modify the WHERE clause in my SQL query?
This seems like such a straight-forward part of the report design, but I'm fairly new to Crystal Reports and I only have experience with modifying reports someone else has already written. In this particular case, I just need to modify the WHERE clause of the SQL query. I can select Show SQL Query and see what statement is being used to select data, but I can't find where to modify it since it's grayed out. I see how to change the selection criteria, parameters, grouping, etc...just not the WHERE clause. The report is linked to a database used for reporting with a table created and populated by a stored procedure. I don't need to modify the stored procedure because the data I want to filter by is currently in the table--I just don't know how to filter by what I need. Here's part of the query:
SELECT "rpt_dist"."startdate", "rpt_dist"."transtype", "rpt_dist"."laborcode", "rpt_dist"."crewid", "rpt_dist"."regularhrs" FROM "Reporting"."dbo"."rpt_dist" "rpt_dist"
WHERE (rpt_dist."transtype" <> 'WORK' AND rpt_dist."transtype" <> 'WMATL') AND rpt_dist."laborcode" LIKE 'S%' AND (rpt_dist."crewid" = 'HOUS' OR rpt_dist."crewid" = 'HOUS2' ...
I would like to add another crewid to the WHERE clause. Thanks for any input.1.Open the report in the crystal designer
2.Go to the field explorer(if hidden go to view menu->field explorer)
3.Rt. click on the database fields->choose database expert
4.Now you will see 2 columns-Available DataSource and Selected Tables
5.Rt. click on the object(ex.command) available in the Selected Tables column->Choose Edit command
6.A new Modify Command window will appear,here you can edit your SQL Query
I get to step 4 and I see the two columns including my database and the report table, but there is no command object available. If I right-click on my table, I can just view the Properties. ??
As for the other tip to modify the record selection: I don't see anywhere the other crewid values are set and if I add the one I'm missing, it doesn't modify the existing SQL Query and when I preview the report it throws off the results so that no data displays??
I'm using Crystal Reports 11.5 if that makes a difference. Thanks again. -
How to dynamically update columns in a where clause to a SQL query in OSB?
Hi Gurus,
I have a requirement where in we need to dynamically update a where clause to a SQL query in OSB(11.1.1.6.0).
For example:
If the JCA sql string is "select * from emp where emp_id = 100 and emp_status ='Permanent'" now i want to change this where clause and the new query has to be like "select * from emp where emp_name like 'S%' and emp_dept like 'IT' ". basically we need to change the where clause dynamically.
We can also use "fn-bea:execute-sql()" in a xquery but I don't want to use this function as creates a new connection.
I have done some home work and found out --> as per the DOC "http://docs.oracle.com/cd/E23943_01/dev.1111/e15866/jca.htm#OSBDV943" section: "25.5.2 JCA Transport Configuration for Proxy and Business Services", when a business service is created by using JCA, we can see Interaction Spec Properties under JCA Transport Tab. This will have a property "SqlString' and we can over ride it. But I am unable to figure out how to over ride the value. I have tried by using Transport Headers activity but no luck. Please guide me how to achieve this?
Thanks in advance
SuryaI solved my problem.
In my header renderer, I simply added a line to set the text to the object value "label.setText( (String) value );" (where label is an instance of a JLabel.
Thank you to who took some time to think about it.
Marc -
How to set dynamic WHERE clause to VO from backingBean?
Hi,
Can any one let me know the best way to add the dynamic WHERE clause in to VO query.
I have created AM (with AMImpl.java) & VO (with VOImpl.java & VORowImpl.java) in my model project. I suppose to set the WHERE condition at runtime while the user click the search button. I am handling the user button click at UI layer backingBean. From the backing bean I could able to get the objct of the VO and set the where clause by below code.
ValueExpression valueExp = elFactory.createValueExpression(elContext, "#{bindings.UserSearchVO1Iterator}", Object.class);
DCIteratorBinding dcIter = (DCIteratorBinding)valueExp.getValue(elContext);
ViewObject userSearchVO = dcIter.getViewObject();
userSearchVO.setWhereClause("lower(usr_login) LIKE ':1' and usr_udf_suid like ':2' ");
userSearchVO.executeQuery();But as I fear this is not the right way to do it. So I am creating the cutom method inside the VOImpl.java and triggring that method by creating one more cutom method in AMImpl.java. But I dont know how to invoke this AM method from backingBean.
AMImpl method
public void initDetails()
UserSearchVOImpl vo = getUserSearchVO1();
vo.initQuery();
VOImpl method
public void initQuery()
setWhereClause("lower(usr_login) LIKE 'a%' and usr_udf_suid like '%1144%'");
executeQuery();
}Can any one guide me which is the best way to set the where clause to VO? How to call the AM method from backingBean?
Thanks
klni am new to oracle 11g i writing a stored procedure in which i have made use of case in where clause to pass my parameter value v_toStoreID
i have googled a lot regarding that i found that to use case in where clause it should be like this
where
case column_value
when 0
then value1
else
value2
end
this my query
SELECT ITMID as ItemId,
NVL(OrderDtl.PackageID, 0) PackageId,
OrderDtl.OrdDtlID,
(CASE NVL(OrderDtl.PackageID, 0)
WHEN 0
THEN 1
ELSE 0
END) as PackageFlag,
ivitem.Code ItemCode,
ivitem.ITMNAME AS itemName,
IvPatientIssueMst.IssueNo Issue_No,
to_char(Issuedate, 'DD/MM/YYYY') IssueDate,
OrderDtl.OrdQty,
NVL(OrderDtl.AllocationID, 0) Package,
OrderDtl.ServiceAmount MRP
FROM IvPatientIssueMst
JOIN OrderMst
ON IvPatientIssueMst.OrderId = OrderMst.OrdId
JOIN OrderDtl
ON OrderDtl.OrdID = OrderMst.OrdId
JOIN ivitem
ON ivitem.ITMID = OrderDtl.DrugId
LEFT JOIN IVPatientIndentMst
ON IVPatientIndentMst.IndentID = IvPatientIssueMst.IndentId
WHERE OrderMst.OrdVisitID = 395899
AND
*(CASE IvPatientIssueMst.StoreId*
when NVL(IvPatientIssueMst.StoreId, 0)=0
THEN v_toStoreID
ELSE IVPatientIndentMst.ToStoreID
END)
ORDER BY ivitem.ITMNAME;
it is not working please someone help -
What happens u0093Updateu0094 command is used without where clause ?
Hi
What happens Update command is used without where clause ?
thank youHi subash,
chk this help
UPDATE dbtab SET f1 ... fn. or
UPDATE (dbtabname) SET f1 ... fn.
Extras:
1. ... WHERE condition
2. ... CLIENT SPECIFIED
3. ... CONNECTION con
Effect
Updates values in a database table. <b>If there is no WHERE clause, all lines (in the current client) are updated.</b> If a WHERE condition is specified, only thoserecords which satisfy the WHERE condition are updated. -
Trying to use a where clause from a table
hi,
I have a report and I need to use a where clause that is archived in a table, it is a different one depending on the row (colour=blue or number = 88..) I have tryied with ref cursor, dinamis sql, functions, packages and could not get it, any suggestion??
thanksYou may use Lexical Rerefences: "Lexical references are placeholders for text that you embed in a SELECT statement. You can use lexical references to replace the clauses appearing after SELECT, FROM, WHERE, GROUP BY, ORDER BY, HAVING, CONNECT BY, and START WITH....."
-
How to use "Order by" clause dynamically on LOV values in 10g r2 forms
Hi ,
I have following requirement,please guide me.
1 Create a List Of Values with 2 fields, Code and Description
2. Do not use order by clause in record Group Query
3. Attach this LOV to a field in Form
4. When user invokes the LOV user will see two fields in LOV with header as Code and Description
5. Now when user clicks on Column Header “Code” then LOV should be sorted on Code
6. And if User clicks on Column Header “Description” then LOV should be sorted on Description
Thanks in Advance.Kindly post this problem in this forum ->
[Forms Forum|http://forums.oracle.com/forums/forum.jspa?forumID=82]
And, close this thread by marked it as answered. ;)
Regards.
Satyaki De. -
How to use outer join condition in my below query.
Hi All,
How to use outer join condition in my below query.
In the table APPS_JP.GEDIS_OFFER_HEADER goh I have more records
in the table APPS_JP.GEDIS_ORDER_BUILDS gob I have less number of records.
I want all the records from APPS_JP.GEDIS_OFFER_HEADER goh
including other conditions.
I have tried goh.OFFER_NO=gob.OFFER_NO(+) but same result.
[code]SELECT GOH.ORIG_SYSTEM,
gsp.USER_NAME,
goh.ORDER_NO,
goh.OMEGA_ORDER_NUMBER,
goh.ORDER_TYPE,
gc.CUSTOMER_ID,
gc.OMEGA_CUSTOMER_NUMBER,
CASE WHEN gc.PRIVATE = 'N' THEN gc.CUSTOMER_NAME ELSE '' END
AS COMPANY_NAME,
goh.ORDER_STATUS,
goh.TOTAL_SELLING_PRICE,
goh.TOTAL_MARGIN,
ga1.ADDRESS1
|| ','
|| ga1.ADDRESS2
|| ','
|| ga1.ADDRESS3
|| ','
|| ga1.POSTAL_CODE
|| ','
|| ga1.CITY
AS SHIPPING_ADDRESS,
ga2.ADDRESS1
|| ','
|| ga2.ADDRESS2
|| ','
|| ga2.ADDRESS3
|| ','
|| ga2.POSTAL_CODE
|| ','
|| ga2.CITY
AS BILLING_ADDRESS,
ga.ADDRESS_ID,
gol.DESCRIPTION,
APPS_JP.TZ.to_local_date (goh.OFFER_DATE, goh.OFFER_DATE_UTC)
AS OFFER_DATE,
gc.LEVEL_8,
goh.NO_OF_BUILDS,
gob.SFDC_ID,
goh.PURCHASE_ORDER_NO AS PO,
gc1.CUSTOMER_NAME AS END_USAGE,
gol.LOB,
goh.TOTAL_MARGIN_PCT,
goh.TOTAL_DISCOUNT,
goh.TOTAL_DISCOUNT_PCT
FROM APPS_JP.GEDIS_OFFER_HEADER goh,
APPS_JP.GEDIS_ORDER_BUILDS gob,
APPS_JP.GEDIS_ORDER_LINES gol,
APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER gorc,
APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER ship,
APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER bill,
APPS_JP.GEDIS_CUSTOMER gc,
APPS_JP.GEDIS_CUSTOMER gc1,
APPS_JP.GEDIS_CONTACT gct,
APPS_JP.GEDIS_ADDRESS ga,
APPS_JP.GEDIS_ADDRESS_NORM ga1,
APPS_JP.GEDIS_ADDRESS_NORM ga2,
(SELECT DISTINCT SALESPERSON_ID, USER_NAME
FROM APPS_JP.GEDIS_SALESPERSON
WHERE SALESPERSON_ID IN
(SELECT TO_NUMBER (COLUMN_VALUE) AS SALESPERSON_ID
FROM TABLE (APPS_GLOBAL.SplitString ('337309'))))
gsp
WHERE goh.ORDER_NO <> 0
AND goh.OFFER_NO <> 0
AND goh.OFFER_NO=gol.OFFER_NO
AND gol.BUILD_NO = 1
AND gol.LINE_NO = 1
AND goh.OFFER_NO=gob.OFFER_NO
AND gob.BUILD_NO = 1
AND goh.OFFER_NO = gorc.OFFER_NO
AND gct.CONTACT_ID = gorc.CONTACT_ID
AND ga.CUSTOMER_ID = gc.CUSTOMER_ID
AND ga.PRIMARY = 'Y'
AND goh.LEAD_SALESPERSON=gsp.SALESPERSON_ID
AND goh.OFFER_NO = ship.OFFER_NO
AND ship.RELATION_TYPE = 'SHIP'
AND ga1.ADDRESS_ID = ship.ADDRESS_ID
AND ga1.CUSTOMER_ID = gc1.CUSTOMER_ID
AND goh.OFFER_NO = bill.OFFER_NO
AND bill.RELATION_TYPE = 'BILL'
AND ga2.ADDRESS_ID = bill.ADDRESS_ID
AND goh.OFFER_DATE BETWEEN APPS_JP.TZ.LOCAL_TO_DB_DATE (
SYSDATE - 30
AND APPS_JP.TZ.LOCAL_TO_DB_DATE (SYSDATE)
AND gorc.RELATION_TYPE = 'BASE'
AND gorc.CUSTOMER_ID = gc.CUSTOMER_ID
AND goh.SALES_CHANNEL = gc.SALES_CHANNEL
AND gc.SALES_CHANNEL = 'SMB'
AND goh.LEAD_SALESPERSON IN (goh.CREATED_BY, goh.LEAD_SALESPERSON)
ORDER BY goh.OFFER_NO;[/code]
Please help me how to use this outer join condition.
Thanks in advance.Hi,
If you want all the rows from goh, then you don't want any conditions like goh.OFFER_NO <> 0.
Make all the joins to goh outer joins, and make all conditions that apply to any tables joined to goh (or to tables joined to them) part of the join condition, like this:
FROM APPS_JP.GEDIS_OFFER_HEADER goh
LEFT OUTER JOIN APPS_JP.GEDIS_ORDER_BUILDS gob ON gob.OFFER_NO = goh.OFFER_NO
AND gob.BUILD_NO = 1
LEFT OUTER JOIN APPS_JP.GEDIS_ORDER_LINES gol ON gol.OFFER_NO = goh.OFFER_NO
AND gol.BUILD_NO = 1
AND gol.LINE_NO = 1
LEFT OUTER JOIN APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER
gorc ...
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
Simplify the problem as much as possible. For example, do you really need all those tables to show what the problem is? Of course, you need them in tyour real query, but if you understand a solution that only involves 4 or 5 tables, you'll know how to apply it to any number of tables.
Explain, using specific examples, how you get those results from that data.Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ https://forums.oracle.com/message/9362002#9362002 -
How to dynamically build where clause in Linq
Hello everyone,
Oracle DB:11gR2
Oracle Client: 11.2.0.3.0 (ODP.NET)
Oracle Developer Tools for Visual Studio
VS 2010 (C#)
In a Windows Form, we need to query the data based on the values of dropdown listboxes, which user will select.
Let's say, two combox, one is for Department and one is for Salary
Department:
-1 All
10 Department 1
20 Department 2
30 Department 3
Salary:
-1 All
1 < 20000
2 20000 to 50000
3 50000 to 100000
4 > 100000
Here is C# code to query data:
using (var myEDMctx = new HREntities())
var LINQrslt = from emp in myEDMctx.EMPLOYEES
select emp;
The default values for both combox should be All.
How to write the dynamic where clause for this LINQ?
Thanks in advance!!!There is nothing Oracle-specific about dynamic LINQ queries. Dynamic LINQ queries are handled all the same way, no matter which data source you use. Microsoft describes how to use Dynamic LINQ here:
http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx
http://weblogs.asp.net/davidfowler/archive/2010/08/19/dynamic-linq-part-2-evolution.aspx -
How to set dynamic where clause in ADF?
Hi,
I have a View object called BillInfoVO. This has
all the information about who created the request, the time , status etc.,
I need to display this VO in a jsp. But before I display, i need to fileter this
VO results with different where clauses according to the role of the user.
For example, if the role is admin, then
where clause should be 'status = 'Completed, and created by = 'Current user'
If the role is requestor, then
the where clause should be
sales manager id = 'Current user' and
Status != Complete etc.,
Could any one please let me know how I can
dynamically set the where clause to filter the appropirate
result row set in the jsp?
Your help will be greatly appreciated.
Thanks,
venkiYou'll create a service method in your AM that will use the setWhereClause method of a viewobject.
Then you'll expose it as a client method.
Then you'll drag it from your data-control onto a button in your JSF page that will call your page for the query.
More about service methods here:
http://download.oracle.com/docs/html/B25947_01/bcservices003.htm#sm0206
http://download.oracle.com/docs/html/B25947_01/bcquerying008.htm#sthref286 -
How to set the where clause of a value set on the basis of a form field
I am using a DFF(Descriptive FlexField), which needs to display the value of a certain column(say columnA) on the basis of the value of another column(say columnB).
So i have created a value set which points to the table which has both these columns, and the DFF uses this value set. However, the problem is that I have not put any where clause in the value set, because of which i cannot handle the exact fetch returns more than one rows error.
The query has to be as follows:
select ColumnA from tbl where ColumnB = [ a form value ];
What I want to know is how can i get the value of a certain field of a certain block of the form in the above query.
Edited by: 981615 on Jan 14, 2013 12:48 AM
Edited by: 981615 on Jan 14, 2013 12:48 AMJust have a look over these two statements if it solves your problem
one time where clause
Set_Block_Property('BLOCK_NAME',ONETIME_WHERE,your form item);
dynamic where clause
set_block_property('BLOCK_NAME'default_where, your form itme)
you can where clause at run time from any procedure or some triggers -
How to edit the where clause of View object in search example dynamically
Hi,
I am new to OA Framework. Can anybody please tell me how can I assign the where clause dynamically. I want to search only those rows whose creation date is between a 'Date form' and 'Date to' inputs from the search page
Thanks
Anupamuser567342 ,
I will advice u again pls refer dev guide, there u can find code sample for ur requirement, which can be accomplished using stringbuffer.
--Mukul -
Case stament use in where clause grive error
i want to use this conditions but gives error. Please give me the solution of it
WHERE
CASE
WHEN CANCELLED_DATE IS NULL THEN
TO_DATE(INV_GL_DATE,'DD-MON-YY') <= TO_DATE (:P_DATE1,'DD-MON-YY')
ELSE
TO_DATE(INV_GL_DATE,'DD-MON-YY') >= TO_DATE(:P_DATE1,'DD-MON-YY')
END) --- <= TO_DATE(:P_DATE1,'DD-MON-YY')Hi,
Remember that a CASE expression always evaluates to a single value in one of the SQL datatypes, such as VARCHAR2, NUMBER or DATE. (There is no Boolean datatype in SQL.)
You can't say
WHERE CASE ... END;for the same reason that you can't say
WHERE 'Hello, world!';orWHERE 100;or
WHERE SYSDATE;CASE expressions are really valuable because they allow you do perform IF-THEN-ELSE logic in places where you normally can't, like the SELECT clause.
The WHERE clause is a place where you can perform IF-THEN-ELSE logic anyway, so there's rarely a need for a CASE expression in a WHERE clause. It's just as efficient and just as clear (if not more so) to put all your conditions directly in the WHERE clause, like Max demonstrated.
Edited by: Frank Kulash on Feb 26, 2010 10:13 AM
user11995078 wrote:
Thanks Dear But how can we use with case and decodeWhy do you want to?
CASE does not help in this problem, any more than regular expressions or CONNECT BY or MODEL help. They are all great tools for particular jobs, but not for this job. Asking "How can I use CASE to do this?" Is like asking "How can I use a hammer to tighten a bolt?" Perhaps there is a way, but it's likely to be contrived and ridiculous.
Here's the least ridiculous way I can think of:
WHERE ( TO_DATE (INV_GL_DATE, 'DD-MON-YY')
- TO_DATE (:P_DATE1, 'DD-MON-YY')
) * CASE
WHEN cancelled_date IS NULL THEN 1
` ELSE -1
END <= 0
Maybe you are looking for
-
GR material document to be shown in the corresponding Accounting document
Is there a user exit available or a config to actually get the Goods receipt document to be shown in the corresponding accouting line item document in the Text field (BSEG-SGTXT) for example.
-
Hello, I need to do Market Basket Analysis for my data, and have a working R script when using it in R Studio. I need to transfer that R script to Azure ML Studio. I read in another posting that the arules package is pre-installed and that I need t
-
How can I get videos off my iPhone and onto iPad2 for editing?
I have backed up the videos into a folder, and I load them into a folder that I sync with the iPad but I cannot view them... Any suggestions.
-
What is the LibraryTEST file?
It's showing up on one of our laptops that is having iPhoto issues. (I know I need to rebuild the library to start fixing it)
-
Message filters vs Content Filters
Differences: 1. Message filters occur earlier in the email pipeline than content filters. Message filters before the email goes into the workqueue. The content filters occur inside the workqueue. 2. Message filters are currently only administered fro