SQLPLUS newbie: SELECT query help
Hi:
The following line prints all the records I am expecting to see.
select d.device_id,c.ORG_NAME
from device d, customer c
where d.device_type in ('DOS') and d.cust_id = c.cust_id;But the following line doesn't print any records since the there are no entries in contact table. I want this to print all the records that were printed for the above statement and if available co.FIRSTNAME as well.
select d.device_id,c.ORG_NAME,co.FIRSTNAME
from device d, customer c,contact co
where d.device_type in ('DOS') and d.cust_id = c.cust_id and co.CONTACT_ID = d.device_id;Thanks in advance
Ravi
Use outer join:
select d.device_id,c.ORG_NAME,co.FIRSTNAME
from device d, customer c,contact co
where d.device_type in ('DOS') and d.cust_id = c.cust_id and co.CONTACT_ID(+) = d.device_id;SY.
Similar Messages
-
Select query help for Sales order
Hi Experts,
I have to write a select query to fetch sales orders which are open along with the quantities which are open ( not delivered). What would the best approach for this?
Any help is appreciated. Expecting code samples....Thanks
Thanks
Rickyhi,
do like this,
write a select query for vbak and vbuk as follows.
delivery status field is <b>lfstk</b> from <b>vbuk</b>,
and relation field is <b>vbeln</b> from the both the tables.
reward points if useful,
regards,
seshu. -
SQL SELECT Query Help ..Please its very Urgent!!
Hi All,
I am having Oracle Database whice is storing 1000's of records daily.
I need to select some information based on date and time.
I am having two coloumns for Date and time. The first column(testDate) of type Date stores date as MM/DD/YY format and the second column(testTime)of type Numeric stores the time in seconds.
The Example data is :
testDate ------=-- testTime
11/12/2002 --- 35000
11/12/2002 --- 43000
11/12/2002 --- 45000
11/12/2002 --- 75000
11/13/2002 --- 2000
11/13/2002 --- 3500
11/13/2002 --- 4300
11/13/2002 --- 9800
11/13/2002 --- 23000
11/14/2002 --- 5000
11/14/2002 --- 10000
11/14/2002 --- 15000
How can i write a SELECT Query to get the records of specific date and seconds to next day specific date and seconds.I mean i want all the records between 11/12/2002 --- 43000 seconds to 11/14/2002 --- 1000 seconds.
If any one helps me in this regard iam very thank full to them.Its very urgent for me.
ThanksHi m7nra,
I used the query as
SELECT * FROM table
WHERE testDate + (testTime/(24*60*60)) BETWEEN TO_DATE('MM/DD/YYYY','12.11.2002') AND TO_DATE('MM/DD/YYYY','14.11.2002')
its giving DATE FORMAT NOT RECOGNIZED error.
The Example data is :
testDate ------=-- testTime
11/12/2002 --- 35000
11/12/2002 --- 43000
11/12/2002 --- 45000
11/12/2002 --- 75000
11/13/2002 --- 2000
11/13/2002 --- 3500
11/13/2002 --- 4300
11/13/2002 --- 9800
11/13/2002 --- 23000
11/14/2002 --- 5000
11/14/2002 --- 10000
11/14/2002 --- 15000
infact i need all the records between 11/12/2002 --- 43000 seconds to 11/14/2002 --- 1000 seconds.
Please help me to find a full query beacuse iam very new to Oracle.
Thanks,
S R Mannava -
I need help with a SELECT query - help!
Hello, I need help with a select statement.
I have a table with 2 fields as shown below
Name | Type
John | 1
John | 2
John | 3
Paul | 1
Paul | 2
Paul | 3
Mark | 1
Mark | 2
I need a query that returns everything where the name has type 1 or 2 but not type 3. So in the example above the qery should bring back all the "Mark" records.
Thanks,
IanOr, if the types are sequential from 1 upwards you could simply do:-
SQL> create table t as
2 select 'John' as name, 1 as type from dual union
3 select 'John',2 from dual union
4 select 'John',3 from dual union
5 select 'Paul',1 from dual union
6 select 'Paul',2 from dual union
7 select 'Paul',3 from dual union
8 select 'Paul',4 from dual union
9 select 'Mark',1 from dual union
10 select 'Mark',2 from dual;
Table created.
SQL> select name
2 from t
3 group by name
4 having count(*) <= 2;
NAME
Mark
SQL>Or another alternative if they aren't sequential:
SQL> ed
Wrote file afiedt.buf
1 select name from (
2 select name, max(type) t
3 from t
4 group by name
5 )
6* where t < 3
SQL> /
NAME
Mark
SQL>Message was edited by:
blushadow -
Hello:
I need to write a query which identifies the patients who exist in the master table for a given organization and trait and do not exist in the final table.
For example, for organization 499 and trait 43926, I have a total of 119 patients. After some processing, out of these 119 patients, only 106 patients get inserted into the final_traits table.
This leaves us with a difference of 13 patients. I want a query that will give me this list of 13 patients.
In order to achieve this, I need to use three tables:
1. Master_traits which contains the entire patient population. The field needed from this table is dwkey_patient.
2. Patient which contains the demographic info. The three fields needed from this table are dwkey_patient, patient_key, and name.
3. Final_traits which contains the detail trait info. The field needed from here is patient_key.
To retrieve the 119 patients along with their names, the first join needs to be between “master_traits” and “patient” using the dwkey_patient field.
From these 119 patients, to determine which ones did NOT get inserted into the final_traits table, the second join will be between “patient” and “final_traits” using the patient_key field. This should give me 13 patients.
So far, I have the portion of the query which gives me the total population of 119.
select a.dwkey_patient, b.patient_key, b.name
from master_traits a, patient b
where a.dwkey_patient = b.dwkey_patient
and a.dwkey_org = 499
and a.dwkey_approval > 0
and a.dwkey_traittype = 43926
and a.out_of_range is null
order by dwkey_patient asc;
[/code]
I am having a tough time getting the second portion of the query to show me the 13 patients who were not inserted.
Can someone help?
Thanks.Well,
It works for me...
MHO%xe> with master_traits as
2 ( select 1234 dwkey_patient from dual union all
3 select 2345 from dual union all
4 select 3456 from dual union all
5 select 4567 from dual union all
6 select 5678 from dual
7 )
8 , patient as
9 ( select 1234 dwkey_patient, 900 patient_key, 'smith' name from dual union all
10 select 2345, 901, 'jones' name from dual union all
11 select 3456, 902, 'murphy' name from dual union all
12 select 4567, 903, 'brown' name from dual union all
13 select 5678, 904, 'miller' name from dual
14 )
15 , final_traits as
16 ( select 900 patient_key from dual union all
17 select 901 from dual union all
18 select 903 from dual
19 ) -- actual query starts here:
20 select a.dwkey_patient, b.patient_key, b.name
21 from master_traits a
22 , patient b
23 , final_traits c
24 where a.dwkey_patient = b.dwkey_patient
25 -- and a.dwkey_org = 499
26 -- and a.dwkey_approval > 0
27 -- and a.dwkey_traittype = 43926
28 -- and a.out_of_range is null
29 and b.patient_key = c.patient_key(+)
30 and c.patient_key is null
31 ;
DWKEY_PATIENT PATIENT_KEY NAME
5678 904 miller
3456 902 murphySo, you might need to adjust your WHERE clause I commented out in above example...
MHO%xe> with master_traits as
2 ( select 1234 dwkey_patient from dual union all
3 select 2345 from dual union all
4 select 3456 from dual union all
5 select 4567 from dual union all
6 select 5678 from dual
7 )
8 , patient as
9 ( select 1234 dwkey_patient, 900 patient_key, 'smith' name from dual union all
10 select 2345, 901, 'jones' name from dual union all
11 select 3456, 902, 'murphy' name from dual union all
12 select 4567, 903, 'brown' name from dual union all
13 select 5678, 904, 'miller' name from dual
14 )
15 , final_traits as
16 ( select 900 patient_key from dual union all
17 select 901 from dual union all
18 select 903 from dual
19 )
20 select a.dwkey_patient, b.patient_key, b.name
21 from master_traits a, patient b
22 where a.dwkey_patient = b.dwkey_patient
23 -- and a.dwkey_org = 499
24 -- and a.dwkey_approval > 0
25 -- and a.dwkey_traittype = 43926
26 -- and a.out_of_range is null
27 and not exists ( select null
28 from final_traits c
29 where c.patient_key = b.patient_key )
30 ;
DWKEY_PATIENT PATIENT_KEY NAME
5678 904 miller
3456 902 murphyWorks too (ofcourse)
Edited by: hoek on Jun 4, 2009 8:37 PM -
I have to do a task of finding records which matches the following logic.
My table has PID varchar(15), Amount varchar (50),Status varchar(20) columns.
Each PID can go thru changes in a period of time, in my case i dont have a data range I just have a flatfile which consists of three types of PID`s
123456 = Original_PID, Reversal =123456R1,Adjustment= 123456A1.
Basically What I am trying to find out if there are any original PID`s which has a Reversal or an Adjustment.
here`s the code I have started on... Can someone help me get it finished?
select R1. pid,a1.pid,org.pid from (
select SUBSTRING(Pid,1,11)as Original_PID, status, paid_amount as Amount from dbo.Q2STATUS)org
inner join (select SUBSTRING(Pid,1,13)as Original_Icn,status,paid_amount from dbo.Q2STATUS
where SUBSTRING(Pid,12,2) ='R1')r1 on r1.pid=org.pid
inner join (select SUBSTRING(claim_id,1,13)as Original_Icn,status,paid_amount from dbo.Q2STATUS
where SUBSTRING(Pid,12,2) ='A1')A1 on a1.Pid=org.PID
FMHi,
Please check following item
It uses a
SQL string function, please create it first
create table Q2STATUS (Pid nvarchar(200), Status varchar(20), paid_amount int)
insert into Q2STATUS select '123456 = Original_PID, Reversal =123456R1, Adjustment= 123456A1',NULL,250
with cte2 as (
select rn = row_number() over (order by pid), * from Q2STATUS
), cte as (
select cte2.*, s.id typeid, v.*
from cte2
cross apply dbo.split(cte2.Pid, ',') s
cross apply dbo.split(s.val, '=') v
), cte3 as (
select
rn, pid, status, paid_amount, max(pidtype) pidtype, max(pidval) pidval
from (
select
rn, Pid, status, paid_amount, typeid,
case when (typeid = 1 and id = 2) or (typeid <> 1 and id = 1) then ltrim(rtrim(val)) else null end as pidtype,
case when (typeid = 1 and id = 1) or (typeid <> 1 and id = 2) then ltrim(rtrim(val)) else null end as pidval
from cte
) g
group by rn, pid, status, paid_amount, typeid
select
cte2.rn, cte2.pid,
cte3.pidval as 'Original_PID',
cte4.pidval as 'Reversal',
cte5.pidval as 'Adjustment'
from cte2
left join cte3 on cte3.rn = cte2.rn and pidtype = 'Original_PID'
left join cte3 as cte4 on cte4.rn = cte2.rn and cte4.pidtype = 'Reversal'
left join cte3 as cte5 on cte5.rn = cte2.rn and cte5.pidtype = 'Adjustment'
Here is the result,
Please note that I have used
SQL CTE expressions a lot in the SQL query to prevent usage of sub-select and temp tables.
There is also a
SQL ROW_NUMBER() function used in the first SELECT statement to distinquish all items from each other instead of using the PID column value. Perhaps you have already an ID key column, you can use it too
SQL Server, SQL Server 2012 Denali and T-SQL Tutorials -
I know this is a SQL question but I can't seem to figure this
out. The below SQL query will run without error however it will
output the company_name for every row which I dont want.
So basicly it currently outputs like this now:
company_name - apple
company_name - dell
BUT want it to output like this:
company_name - apple,dell
MY CURRENT QUERY:
SELECT d.disputeid, t.company_name, t.tlid, t.type,
l.description
FROM member_disputes d, member_tradeline t, letters l
WHERE d.fk_tlid = t.tlid
AND d.fk_letterid = l.letterid
AND d.fk_memberid = #GetAuthUser()#
Any help much appreciatedquote:
Originally posted by:
LionelR
I know this is a SQL question but I can't seem to figure this
out. The below SQL query will run without error however it will
output the company_name for every row which I dont want.
So basicly it currently outputs like this now:
company_name - apple
company_name - dell
BUT want it to output like this:
company_name - apple,dell
MY CURRENT QUERY:
SELECT d.disputeid, t.company_name, t.tlid, t.type,
l.description
FROM member_disputes d, member_tradeline t, letters l
WHERE d.fk_tlid = t.tlid
AND d.fk_letterid = l.letterid
AND d.fk_memberid = #GetAuthUser()#
Any help much appreciated
Suddenly a light bulb illuminated over my head.
<cfouput>
company_name - #ValueList(yourquery.company_name)#
</cfoutput>
If that doesn't work, either change this, "t.company_name" to
"company_name" or "t.company_name as company_name".
I can't believe none of us thought of this earlier. -
Problem with select query:help
SELECT url,SUM(data_received) xyz FROM logs GROUP BY url ORDER BY xyz desc
when i triedthe above query in the worksheet it works fine but when i write same query in code i get this error.
myjsp page has this code.
<%while (rset.next())
out.println("<tr>");
out.println("<td>" +
rset.getString(1) + "</td><td>" +
rset.getInt(2) + "</td><td> " +
"</td>");
out.println("<tr>");
%>
This is the error
500 Internal Server Error
java.sql.SQLException: Invalid column name at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:138) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:175) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:240) at oracle.jdbc.driver.OracleStatement.get_column_index(OracleStatement.java:3201) at oracle.jdbc.driver.OracleResultSetImpl.findColumn(OracleResultSetImpl.java:1880) at oracle.jdbc.driver.ScrollableResultSet.findColumn(ScrollableResultSet.java:1308) at oracle.jdbc.driver.OracleResultSet.getInt(OracleResultSet.java:1618) at list_action._jspService(_list__action.java:67) [list_action.jsp] at com.orionserver[Oracle Containers for J2EE 10g (10.1.3.0.0) ].http.OrionHttpJspPage.service(OrionHttpJspPage.java:60) at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:416) at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:478) at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:401) at javax.servlet.http.HttpServlet.service(HttpServlet.java:856) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:719) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:376) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:870) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:451) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:218) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:119) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112) at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260) at oracle.oc4j.network.ServerSocketAcceptHandler.procClientSocket(ServerSocketAcceptHandler.java:230) at oracle.oc4j.network.ServerSocketAcceptHandler.access$800(ServerSocketAcceptHandler.java:33) at oracle.oc4j.network.ServerSocketAcceptHandler$AcceptHandlerHorse.run(ServerSocketAcceptHandler.java:831) at com.evermind[Oracle Containers for J2EE 10g (10.1.3.0.0) ].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303) at java.lang.Thread.run(Thread.java:595)
please helpThis is not the proper forum....
Post this thread to
Java Server Pages (JSP)
Greetings...
Sim -
Need help in writing a select query to pull required data from 3 tables.
Hi,
I have three tables EmpIDs,EmpRoles and LatestRoles. I need to write a select Query to get roles of all employees present in EmpIDs table by referring EmpRoles and LatestRoles.
The condition is first look into table EmpRoles and if it has more than one entry for a particular Employee ID than only need to get the Role from LatestRoles other wise consider
the role from EmpRoles .
Sample Script:
Create Table #EmpIDs
(EmplID int )
Create Table #EmpRoles
(EMPID int,Designation varchar(50))
Create Table #LatestRoles
EmpID int,
Designation varchar(50)
Insert into #EmpIDs values (1),(2),(3)
Insert into #EmpRoles values (1,'Role1'),(2,'Role1'),(2,'Role2'),(3,'Role1')
Insert into #LatestRoles values (2,'Role2')
Employee ID 2 is having two roles defined in EmpRoles so for EmpID 2 need to fetch Role from LatestRoles table and for
remaining ID's need to fetch from EmpRoles .
My Final Output of select query should be like below.
EmpID Role
1 Role1
2 Role2
3 Role1
Please help.
MohanMohan,
Can you check if this answers your requirement:
Create Table #EmpIDs
(EmplID int )
Create Table #EmpRoles
(EMPID int,Designation varchar(50))
Create Table #LatestRoles
EmpID int,
Designation varchar(50)
Insert into #EmpIDs values (1)
Insert into #EmpIDs values (2)
Insert into #EmpIDs values (3)
Insert into #EmpRoles values (1,'Role1')
Insert into #EmpRoles values (2,'Role2')
Insert into #EmpRoles values (2,'Role1')
Insert into #EmpRoles values (3,'Role1')
Insert into #LatestRoles values (2,'Role2')
--Method 1
select e.EmplID,MIN(ISNULL(l.Designation,r.Designation)) as Designation
from #empids e
left join #emproles r on e.emplID=r.EmpID
left join #latestRoles l on e.emplID=l.EmpID
group by e.EmplID
--Method 2
;with cte
as
select distinct e.EmplID,r.Designation,count(*) over(partition by e.emplID) cnt
from #empids e
left join #emproles r on e.emplID=r.EmpID
select emplID,Designation
from cte
where cnt=1
UNION ALL
select a.EmplID,l.Designation
from
(select distinct EmplID from cte where cnt>1) a
join #Latestroles l on a.EmplID=l.EmpID
order by emplID
Thanks,
Jay
<If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'> -
Need help in optimisation for a select query on a large table
Hi Gurus
Please help in optimising the code. It takes 1 hr for 3-4000 records. Its very slow.
My Select is reading from a table which contains 10 Million records.
I am writing the select on large table and Retrieving the values from large tables by comparing my table which has 3-4 k records.
I am pasting the code. please help
Data: wa_i_tab1 type tys_tg_1 .
DATA: i_tab TYPE STANDARD TABLE OF tys_tg_1.
Data : wa_result_pkg type tys_tg_1,
wa_result_pkg1 type tys_tg_1.
SELECT /BIC/ZSETLRUN AGREEMENT /BIC/ZREB_SDAT /BIC/ZLITEM1 from
/BIC/PZREB_SDAT *******************THIS TABLE CONTAINS 10 MILLION RECORDS
into CORRESPONDING FIELDS OF table i_tab
FOR ALL ENTRIES IN RESULT_PACKAGE***************CONTAINS 3000-4000 RECORDS
where
/bic/ZREB_SDAT = RESULT_PACKAGE-/BIC/ZREB_SDAT
AND
AGREEMENT = RESULT_PACKAGE-AGREEMENT
AND /BIC/ZLITEM1 = RESULT_PACKAGE-/BIC/ZLITEM1.
sort RESULT_PACKAGE by AGREEMENT /BIC/ZREB_SDAT /BIC/ZLITEM1.
sort i_tab by AGREEMENT /BIC/ZREB_SDAT /BIC/ZLITEM1.
loop at RESULT_PACKAGE into wa_result_pkg.
read TABLE i_tab INTO wa_i_tab1 with key
/BIC/ZREB_SDAT =
wa_result_pkg-/BIC/ZREB_SDAT
AGREEMENT = wa_result_pkg-AGREEMENT
/BIC/ZLITEM1 = wa_result_pkg-/BIC/ZLITEM1.
IF SY-SUBRC = 0.
move wa_i_tab1-/BIC/ZSETLRUN to
wa_result_pkg-/BIC/ZSETLRUN.
wa_result_pkg1-/BIC/ZSETLRUN = wa_result_pkg-/BIC/ZSETLRUN.
modify RESULT_PACKAGE from wa_result_pkg1
TRANSPORTING /BIC/ZSETLRUN.
ENDIF.
CLEAR: wa_i_tab1,wa_result_pkg1,wa_result_pkg.
endloop.Hi,
1) RESULT_PACKAGE internal table contains any duplicate records or not bassed on the where condotion like below
2) Remove the into CORRESPONDING FIELDS OF table instead of that into table use.
refer the below code is
RESULT_PACKAGE1[] = RESULT_PACKAGE[].
sort RESULT_PACKAGE1 by /BIC/ZREB_SDAT AGREEMENT /BIC/ZLITEM1.
delete adjustant duplicate form RESULT_PACKAGE1 comparing /BIC/ZREB_SDAT AGREEMENT /BIC/ZLITEM1.
SELECT /BIC/ZSETLRUN AGREEMENT /BIC/ZREB_SDAT /BIC/ZLITEM1
from /BIC/PZREB_SDAT
into table i_tab
FOR ALL ENTRIES IN RESULT_PACKAGE1
where
/bic/ZREB_SDAT = RESULT_PACKAGE1-/BIC/ZREB_SDAT
AND
AGREEMENT = RESULT_PACKAGE1-AGREEMENT
AND /BIC/ZLITEM1 = RESULT_PACKAGE1-/BIC/ZLITEM1.
and one more thing your getting 10 million records so use package size in you select query.
Refer the following link also For All Entry for 1 Million Records
Regards,
Dhina..
Edited by: Dhina DMD on Sep 15, 2011 7:17 AM -
Needs help to retrive the last row in a select query without using rownum
Hi ,
i need to retrive the last row from the select sub query without using rownum.
is there any other way to retrive the last row other than the below query.
is that the ROWNUM=1 will always retrive the 1 row of the select query ?
select from*
*(select ename from employee where dept_id=5 order by desc) where rownum=1;*
Please advise.
thanks for your help advance,
regards,
Senthur957595 wrote:
Actually my problem is ithat while selecting the parents hiearchy of the child data using
CONNECT BY PRIOIR query
I need the immediate parent of my child data.
For example my connect BY query returns
AAA --- ROOT
BBB --PARENT -2
CCC --PARENT-1
DDD IS my input child to the connect by query
Immediate parent of my child data "DDD" ---> CCC(parent -1)
i want the data "CCC" from the select query,for that i am taking the last row of the query with rownum.
I got to hear that using ROWNUM to retrive the data will leads to some problem.It is a like a magic number.I am not sure what the problem will be.
So confusing with using this rownum in my query.
Please advice!!!It's not quite clear what you're wanting, but perhaps this may help?
you can select the PRIOR values to get the parent details if you want...
SQL> ed
Wrote file afiedt.buf
1 select empno, lpad(' ',(level-1)*2,' ')||ename as ename, prior empno as mgr
2 from emp
3 connect by mgr = prior empno
4* start with mgr is null
SQL> /
EMPNO ENAME MGR
7839 KING
7566 JONES 7839
7788 SCOTT 7566
7876 ADAMS 7788
7902 FORD 7566
7369 SMITH 7902
7698 BLAKE 7839
7499 ALLEN 7698
7521 WARD 7698
7654 MARTIN 7698
7844 TURNER 7698
7900 JAMES 7698
7782 CLARK 7839
7934 MILLER 7782
14 rows selected.(ok, not the best of examples as the mgr is already known for a row, but it demonstrates you can select prior data) -
Problem in the "select" query....Just check out and help me
Hi there !!
I am getting the following errors while trying to execute the "select" query from JSP page:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state
My code is :
String reg_no=(String)session.getAttribute("reg_no");
ResultSet rs=stmt.executeQuery("SELECT * FROM reg WHERE regno = "+reg_no);
(Note: the "regno" in the database is of numeric datatype)
Try to help me...
Thanx,
Ram.Just so everyone knows:
Ram Mohan joined the forum on 7-Sep-2003 and received
his 25 Dukes for joining.
Since then, he's posted three questions, each one
promising 5-10 Dukes, and never once awarded them.
His strategy seems to be to wave Dukes, ask his
hit-and-run question, and then bolt.
Answer his questions if you wish, but don't do it
expecting Dukes. - MODDuffy, you're getting just as cranky as I have. See what hanging around these forums does to oneself? :) -
Need some help with the Select query.
Need some help with the Select query.
I had created a Z table with the following fields :
ZADS :
MANDT
VKORG
ABGRU.
I had written a select query as below :
select single vkorg abgru from ZADS into it_rej.
IT_REJ is a Work area:
DATA : BEGIN OF IT_REJ,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
This is causing performance issue. They are asking me to include the where condition for this select query.
What should be my select query here?
Please suggest....
Any suggestion will be apprecaiated!
Regards,
DeveloperHello Everybody!
Thank you for all your response!
I had changes this work area into Internal table and changed the select query. PLease let me know if this causes any performance issues?
I had created a Z table with the following fields :
ZADS :
MANDT
VKORG
ABGRU.
I had written a select query as below :
I had removed the select single and insted of using the Structure it_rej, I had changed it into Internal table
select vkorg abgru from ZADS into it_rej.
Earlier :
IT_REJ is a Work area:
DATA : BEGIN OF IT_REJ,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
Now :
DATA : BEGIN OF IT_REJ occurs 0,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
I guess this will fix the issue correct?
PLease suggest!
Regards,
Developer. -
Please help me what other way i can tune this select query..
Hello Guru,
I have a select query which retrieve data from 10 tables and around 4 tables having 2-4 Lac record and rest are having 80,000 - 1 Lac record.
It is taking around 7-8 seconds to fetch 55000 record.
I was strictly told by the client that i should not use HINTS in my query. My query is below. Please help me what other way i can tune this select query..
select
CT.CUST_ID
,CT.ROMANISED_SURNAME
,CT.SURNAME
,CT.ROMANISED_GIVEN_NAME
,CT.GIVEN_NAME
,CT.ROMANISED_MIDDLE_NAME
,CT.MIDDLE_NAME
,CT.ROMANISED_NAME_SUFFIX
,CT.NAME_SUFFIX
,CT.ROMANISED_TITLE
,CT.TITLE
,CT.ROMANISED_NAME_INITIALS
,CT.NAME_INITIALS
,CT.NAME_TEXT
,CT.CUST_JRNY_ID
,RK.REMARK_TYPE
,RK.REMARK_ID+CT.CUST_ID as REMARK_ID
,RK.REMARK_STATUS
,RK.REMARK_TEXT
,RK.HOST_ONLY_IND
,RK.SUPERVISORY_IND
,RK.CUST_COMM_IND
,RK.REMARK_SEQ
,RK.REMARK_CODE
,RK.DEFAULT_CUST_REL_IND
,RK.DEFAULT_FLIGHT_SEG_REL_IND
,RK.IATA_CODE
,RK.ICAO_CODE
,CJ.RECORD_LOCATOR "SITA_RECORD_LOCATOR"
,Cjv.Record_Locator "ORIGINATOR_RECORD_LOCATOR"
,FS.TRAVELLING_GROUP_CODE
,CG.GROUP_NAME
FROM FLIGHT_LEG FL
,CUST_FLIGHT_LEG CFL
,CUST CT
,CUST_REMARK CTR
,REMARK RK
,FLIGHT_SEG_FLIGHT_LEG FSFL
,FLIGHT_SEG FS
,CUST_JRNY CJ
,CUST_JRNY_VERSION CJV
,CUST_GROUP CG
WHERE FL.OPR_FLIGHT_NUMBER = 1--I_OPR_FLIGHT_NUMBER
and FL.HISTORY_VERSION_NUMBER = 0
and FL.DEPARTURE_STATION_CODE = 'DEL'--I_DEPARTURE_STATION_CODE
and FL.DEPARTURE_DATETIME = TO_DATE('10-DEC-2012 18.45.00', 'DD-MON-YYYY HH24.MI.SS')
and FL.OPR_SERVICE_PROVIDER_CODE= 'AI'--i_opr_service_provider_code
and FL.OPR_FLIGHT_SUFFIX = 'A'--NVL(I_OPR_FLIGHT_SUFFIX, FL.OPR_FLIGHT_SUFFIX)
AND FL.FLIGHT_LEG_ID = CFL.FLIGHT_LEG_ID
AND CFL.CUST_ID = CT.CUST_ID
AND FL.FLIGHT_LEG_ID=FSFL.FLIGHT_LEG_ID
AND FSFL.FLIGHT_SEG_ID=FS.FLIGHT_SEG_ID
AND CT.CUST_ID = CTR.CUST_ID(+)
AND CTR.REMARK_ID = RK.REMARK_ID(+)
AND FL.CUST_JRNY_ID = CJ.CUST_JRNY_ID
and CJ.CUST_JRNY_ID = CJV.CUST_JRNY_ID
AND CG.CUST_JRNY_ID(+) = CT.CUST_JRNY_ID
AND CFL.HISTORY_VERSION_NUMBER = 0
AND CT.HISTORY_VERSION_NUMBER = 0
AND NVL(CTR.HISTORY_VERSION_NUMBER,0) = 0
AND NVL(RK.HISTORY_VERSION_NUMBER,0) = 0
AND FS.HISTORY_VERSION_NUMBER = 0
AND FSFL.HISTORY_VERSION_NUMBER = 0
-- AND CJ.HISTORY_VERSION_NUMBER = 0
and CJV.VERSION_NUMBER = 0 --- Need to check
AND NVL(CG.HISTORY_VERSION_NUMBER,0) = 0
order by CT.CUST_JRNY_ID,CT.CUST_ID;
The Tables having record:
select COUNT(*) from FLIGHT_LEG -----241756
select COUNT(*) from CUST_FLIGHT_LEG---632585
select COUNT(*) from CUST---240015
select COUNT(*) from CUST_REMARK---73724
select COUNT(*) from REMARK---73654
select COUNT(*) from FLIGHT_SEG_FLIGHT_LEG---241789
select COUNT(*) from FLIGHT_SEG----260004
select COUNT(*) from CUST_JRNY----74288
select COUNT(*) from CUST_JRNY_VERSION----74477
select COUNT(*) from CUST_GROUP----55819
Thanks,
HP..Plan hash value: 3771714931
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Pstart| Pstop |
| 0 | SELECT STATEMENT | | 10239 | 2949K| | 7515 (1)| 00:01:31 | | |
| 1 | SORT ORDER BY | | 10239 | 2949K| 3160K| 7515 (1)| 00:01:31 | | |
|* 2 | HASH JOIN | | 10239 | 2949K| | 6864 (1)| 00:01:23 | | |
| 3 | PARTITION HASH ALL | | 73687 | 1079K| | 417 (1)| 00:00:06 | 1 | 512 |
|* 4 | TABLE ACCESS FULL | CUST_JRNY_VERSION | 73687 | 1079K| | 417 (1)| 00:00:06 | 1 | 512 |
|* 5 | HASH JOIN | | 10239 | 2799K| | 6445 (1)| 00:01:18 | | |
| 6 | PARTITION HASH ALL | | 73654 | 863K| | 178 (1)| 00:00:03 | 1 | 512 |
| 7 | TABLE ACCESS FULL | CUST_JRNY | 73654 | 863K| | 178 (1)| 00:00:03 | 1 | 512 |
|* 8 | FILTER | | | | | | | | |
|* 9 | HASH JOIN RIGHT OUTER | | 10239 | 2679K| | 6267 (1)| 00:01:16 | | |
| 10 | PARTITION HASH ALL | | 55315 | 756K| | 137 (1)| 00:00:02 | 1 | 512 |
| 11 | TABLE ACCESS FULL | CUST_GROUP | 55315 | 756K| | 137 (1)| 00:00:02 | 1 | 512 |
|* 12 | FILTER | | | | | | | | |
|* 13 | HASH JOIN OUTER | | 10240 | 2540K| 2056K| 6129 (1)| 00:01:14 | | |
|* 14 | FILTER | | | | | | | | |
|* 15 | HASH JOIN RIGHT OUTER | | 10242 | 1930K| | 5531 (1)| 00:01:07 | | |
| 16 | INDEX FAST FULL SCAN | CUST_REMARK_PK | 73677 | 935K| | 190 (0)| 00:00:03 | | |
|* 17 | HASH JOIN | | 10257 | 1802K| | 5339 (1)| 00:01:05 | | |
|* 18 | HASH JOIN | | 10257 | 701K| | 3516 (1)| 00:00:43 | | |
|* 19 | HASH JOIN | | 3963 | 220K| | 2476 (1)| 00:00:30 | | |
|* 20 | HASH JOIN | | 3963 | 181K| | 1300 (1)| 00:00:16 | | |
| 21 | PARTITION HASH ALL | | 3963 | 131K| | 728 (1)| 00:00:09 | 1 | 512 |
|* 22 | TABLE ACCESS FULL | FLIGHT_LEG | 3963 | 131K| | 728 (1)| 00:00:09 | 1 | 512 |
|* 23 | INDEX FAST FULL SCAN| FLIGHT_SEG_FLIGHT_LEG_PK | 240K| 3059K| | 571 (1)| 00:00:07 | | |
| 24 | PARTITION HASH ALL | | 259K| 2531K| | 1175 (1)| 00:00:15 | 1 | 512 |
|* 25 | TABLE ACCESS FULL | FLIGHT_SEG | 259K| 2531K| | 1175 (1)| 00:00:15 | 1 | 512 |
| 26 | PARTITION HASH ALL | | 631K| 8011K| | 1037 (1)| 00:00:13 | 1 | 512 |
|* 27 | TABLE ACCESS FULL | CUST_FLIGHT_LEG | 631K| 8011K| | 1037 (1)| 00:00:13 | 1 | 512 |
| 28 | PARTITION HASH ALL | | 239K| 25M| | 1822 (1)| 00:00:22 | 1 | 512 |
|* 29 | TABLE ACCESS FULL | CUST | 239K| 25M| | 1822 (1)| 00:00:22 | 1 | 512 |
| 30 | PARTITION HASH ALL | | 73623 | 4385K| | 243 (1)| 00:00:03 | 1 | 512 |
| 31 | TABLE ACCESS FULL | REMARK | 73623 | 4385K| | 243 (1)| 00:00:03 | 1 | 512 |
Predicate Information (identified by operation id):
2 - access("CJ"."CUST_JRNY_ID"="CJV"."CUST_JRNY_ID")
4 - filter("CJV"."VERSION_NUMBER"=0)
5 - access("FL"."CUST_JRNY_ID"="CJ"."CUST_JRNY_ID")
8 - filter(NVL("CG"."HISTORY_VERSION_NUMBER",0)=0)
9 - access("CG"."CUST_JRNY_ID"(+)="CT"."CUST_JRNY_ID")
12 - filter(NVL("RK"."HISTORY_VERSION_NUMBER",0)=0)
13 - access("CTR"."REMARK_ID"="RK"."REMARK_ID"(+))
14 - filter(NVL("CTR"."HISTORY_VERSION_NUMBER",0)=0)
15 - access("CT"."CUST_ID"="CTR"."CUST_ID"(+))
17 - access("CFL"."CUST_ID"="CT"."CUST_ID")
18 - access("FL"."FLIGHT_LEG_ID"="CFL"."FLIGHT_LEG_ID")
19 - access("FSFL"."FLIGHT_SEG_ID"="FS"."FLIGHT_SEG_ID")
20 - access("FL"."FLIGHT_LEG_ID"="FSFL"."FLIGHT_LEG_ID")
22 - filter("FL"."DEPARTURE_STATION_CODE"='DEL' AND "FL"."DEPARTURE_DATETIME"=TO_DATE(' 2012-12-10 18:45:00', 'syyyy-mm-dd
hh24:mi:ss') AND "FL"."OPR_SERVICE_PROVIDER_CODE"='AI' AND "FL"."OPR_FLIGHT_NUMBER"=1 AND "FL"."OPR_FLIGHT_SUFFIX"='A' AND
"FL"."HISTORY_VERSION_NUMBER"=0)
23 - filter("FSFL"."HISTORY_VERSION_NUMBER"=0)
25 - filter("FS"."HISTORY_VERSION_NUMBER"=0)
27 - filter("CFL"."HISTORY_VERSION_NUMBER"=0)
29 - filter("CT"."HISTORY_VERSION_NUMBER"=0) -
Urgent - I have written select query between loop and endloop, Ple help out
Can any one help out me on this select query. I have written select query between loop and endloop. When I execute the program it will take too much time in this query. Please help me out. Its very urgent.
LOOP AT l_i_invoices ASSIGNING <l_invoices>.
CLEAR alv_wa.
alv_wa-bukrs = <l_invoices>-bukrs.
alv_wa-gsber = <l_invoices>-gsber.
CLEAR l_instid.
CONCATENATE <l_invoices>-belnr <l_invoices>-gjahr INTO l_instid.
SELECT top_wi_id FROM sww_wi2obj INTO TABLE l_i_swwwihead
WHERE catid = c_catid_business_object
AND instid = l_instid
AND typeid = c_typeid_invoice
AND removed = space
AND ( wi_rh_task = c_task_buyer_message
OR wi_rh_task = c_task_buyer_message2 ).
IF sy-subrc = 0.
<l_invoices>-flag = 'X'.
ELSE.
<l_invoices>-flag = ' '.
ENDIF.
MODIFY l_i_invoices FROM <l_invoices> TRANSPORTING flag
WHERE belnr = <l_invoices>-belnr
AND gjahr = <l_invoices>-gjahr.
APPEND alv_wa TO i_alv.
ENDLOOP.
Thanks in advance.Here is a way to solve this problem.
Choose somewhere before this loop processing to use that select. Therefore, you'll need use FOR ALL ENTRIES <that_loop_table> clause, and in the WHERE condition you need to specify that same fields.
This way, you will have an internal table with all data you'll need to check.
Then, inside your loop statement, use the READ TABLE command with the clause WITH KEY field = value, to read that record and use the value found.
Like this sample:
SELECT bukrs lifnr umsks umskz augdt augbl zuonr gjahr belnr buzei
waers xblnr blart gsber ebeln zfbdt zbd1t zlsch
INTO TABLE tg_bsak
FROM bsak
FOR ALL ENTRIES IN tl_bkpf_sel
WHERE bukrs EQ tl_bkpf_sel-bukrs AND
lifnr IN s_lifnr AND
augbl EQ tl_bkpf_sel-belnr.
LOOP AT tg_bseg INTO wa_bseg.
READ TABLE tg_bsak INTO wa_bsak WITH KEY bukrs = wa_bseg-bukrs
gjahr = wa_bseg-gjahr
belnr = wa_bseg-belnr
BINARY SEARCH.
if sy-subrc = 0.
* do something
endif.
ENDLOOP.
Maybe you are looking for
-
Hi all, the number of SAP Business One HowTos is growing. If you need a hint, you might consider checking here: http://www.itwiki.net/ow.asp?SboHowTo Itwiki is a non-commercial wiki made from developers for developers. Ibai has just added another How
-
"Program is not registered in xi " problem
hello all, we get the error "Program is not registered in xi" when executing the "connection test" via transaction 'sm59' for the relevant RFC connection between our XI and ECC systems. the same test went fine earlier and just went wrong. here is the
-
Who can I talk to for resolution on a bogus charge that has been going on for 6 months!
We have been Verizon customers for over 10 years and have always paid our bills on time. In October my daughter's relatively new cell phone was giving her issues. She took it into the Verizon store in SoHo and the rep noted the issues and sent the
-
Editing software filters/plug-ins not showing in LR 5.4
I have editing software and plug-ins that I use mostly in LR, but now I notice when I use them, the filters don't show up. I have Google Nik Collection, Topaz suite, Photomatix and Perfect Effects 8. I went to my LR preferences >external editing an
-
Error in Precalculation Settings
Hi All, I have created a Precalculated Value set. Now I am creating settings in the query for precalculation broadcasting. While saving the settings, I am getting error: " Required input variables for queries are not available" I am not getting where