Is my query correct?
I am using the below query to get the users who were registered for training sorted by date. Is this query will get correct results who were registered first and then selecting them based on number of seats?
select USER,DEPARTMENT from( select USER,DATE_CREATED,DEPARTMENT from TRAINING where DEPARTMENT="+v1.get(i)+" order by DATE_CREATED) where rownum <= (select seat_nos from SEATS where org_id="+v1.get(i)+" and location='US')
Using row number like that is not a good idea. The ROWNUM pseudo column is only applied after sort results - which make it tricky to use and require an additional pass through the data set as sub select and order by is required to use ROWNUM.
Oracle has analytical functions - including a function called row_number() that allows you to add a row sequence to each row, calculated by grouping and ordering. And do this in a single SQL statement.
For example, if you want to add a sequence to the order in which users registered by department, then it can be done using the following SQL:
select
department,
row_number() over (partition by department order by date_created),
user,
date_created
from training
order by
1,2Read the partition by clause as if it is a GROUP BY clause.
PS. Details are in the [url http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/toc.htm]Oracle® Database SQL Reference manual.
Similar Messages
-
Hello,
I would like to send email notification to users by 3 days in advance before the start date, this is the query I am using to pick the employees, is my sql query correct?
Thanks
select START_DATE,END_DATE
from table where START_DATE >= sysdate + 3 andSTART_DATE<= sysdate + 4from table where START_DATE >= sysdate + 3 andSTART_DATE < sysdate + 4
You should be using L.T. operator and not L.E.
Also, if you are not concerned about the time part in the date fields ( I assume START_DATE is a date field), query with above modification should be all right. -
hi..good evening...
i have
with sale_order as (
select 25 sd_code, 'P01045645' sd_prod_code, 10 sd_qty from dual union all
select 25,'P01400025' , 35 from dual union all
select 25,'P01033691.3', 40 from dual union all
select 25,'P012S62R.2' , 10 from dual union all
select 25,'P012S62R.1' , 5 from dual union all
select 25,'P01045645.4', 25 from dual union all
select 25,'P01045645.4', 35 from dual union all
select 25,'P01033654.9', 55 from dual union all
select 25,'P01033654.5', 250 from dual union all
select 25,'P01033654.5', 10 from dual union all
select 25,'P01033654.2', 25 from dual union all
select 25,'P01033654.8', 20 from dual
select * from sd_order
order by 2;
SD_CODE SD_PROD_COD SD_QTY
25.000 P01033654.2 25.000
25.000 P01033654.5 10.000
25.000 P01033654.5 250.000
25.000 P01033654.8 20.000
25.000 P01033654.9 55.000
25.000 P01033691.3 40.000
25.000 P01045645 10.000
25.000 P01045645.4 35.000
25.000 P01045645.4 25.000
25.000 P012S62R.1 5.000
25.000 P012S62R.2 10.000
25.000 P01400025 35.000
12 rows selected.
with delv_order as (
select 25 do_sd_no, 'P012S62R.1' do_prod_code, 5 do_qty from dual union all
select 25,'P012S62R.2' , 5 from dual
select * from delv_order
order by 2;
DO_SD_NO DO_PROD_CO DO_QTY
25.000 P012S62R.1 5.000
25.000 P012S62R.2 5.000i want to display a query that would produce for me the items yet not delivered.
as can be seen for order no. 25 there are total 12 rows..out of which 2 items are delivered
item P012S62R.1 delivered fully but
item P012S62R.2 is deliverd only half the qty. (5 is still left)
i want the result to be like this;
SD_CODE SD_PROD_COD SD_QTY
25.000 P01033654.2 25.000
25.000 P01033654.5 10.000
25.000 P01033654.5 250.000
25.000 P01033654.8 20.000
25.000 P01033654.9 55.000
25.000 P01033691.3 40.000
25.000 P01045645 10.000
25.000 P01045645.4 35.000
25.000 P01045645.4 25.000
25.000 P012S62R.2 5.000
25.000 P01400025 35.000
11 rowsi wrote this code,,but i am getting duplicate rows for item no..
P01033654.5 & P01045645.4, they have 2 records each on sale_order..
this is my query ;
SELECT a.SD_PROD_CODE,a.SD_QTY, (h.SD_QTY-nvl(d.DOqty,0)) bal_QTY
from sale_order a,
select SD_NO,SD_PROD_CODE,SD_QTY
from sale_order
where Sd_no = 25) h,
select DO_SD_NO,DO_PROD_CODE,sum(nvl(DO_QTY_DISPATCHED,0)) DOqty
from delv_order
where DO_SD_NO = 25
group by DO_SD_no,DO_PROD_CODE) d
WHERE a.SD_PROD_CODE = h.SD_PROD_CODE(+)
and a.SD_PROD_CODE = d.DO_prod_code(+)
and a.SD_no = h.Sd_no(+)
and a.SD_no = d.DO_SD_no(+)
and a.SD_no = 25
and (h.SD_qty-nvl(d.DOqty,0)) > 0
order by 1;
SD_PROD_COD SALED_QTY BAL_QTY
P01033654.2 25.000 25.000
P01033654.5 10.000 10.000
P01033654.5 250.000 250.000
P01033654.5 10.000 250.000
P01033654.5 250.000 10.000
P01033654.8 20.000 20.000
P01033654.9 55.000 55.000
P01033691.3 40.000 40.000
P01045645 10.000 10.000
P01045645.4 25.000 35.000
P01045645.4 35.000 35.000
P01045645.4 25.000 25.000
P01045645.4 35.000 25.000
P012S62R.2 10.000 5.000
P01400025 35.000 35.000
15 rows selected.please suggest with correction on my query..
TYwith sale_order as (
select 25 sd_code, 'P01045645' sd_prod_code, 10 sd_qty from dual union all
select 25,'P01400025' , 35 from dual union all
select 25,'P01033691.3', 40 from dual union all
select 25,'P012S62R.2' , 10 from dual union all
select 25,'P012S62R.1' , 5 from dual union all
select 25,'P01045645.4', 25 from dual union all
select 25,'P01045645.4', 35 from dual union all
select 25,'P01033654.9', 55 from dual union all
select 25,'P01033654.5', 250 from dual union all
select 25,'P01033654.5', 10 from dual union all
select 25,'P01033654.2', 25 from dual union all
select 25,'P01033654.8', 20 from dual
delv_order as (
select 25 do_sd_no, 'P012S62R.1' do_prod_code, 5 do_qty from dual union all
select 25,'P012S62R.2' , 5 from dual
select sd_code,
sd_prod_code,
sd_qty - nvl(do_qty,0) sd_qty
from sale_order left join delv_order
on (sd_code = do_sd_no and sd_prod_code = do_prod_code)
where sd_qty - nvl(do_qty,0) != 0
SD_CODE SD_PROD_COD SD_QTY
25 P012S62R.2 5
25 P01045645 10
25 P01033654.5 10
25 P01033654.5 250
25 P01033654.2 25
25 P01033691.3 40
25 P01045645.4 35
25 P01045645.4 25
25 P01033654.8 20
25 P01400025 35
25 P01033654.9 55
11 rows selected.
SQL> SY. -
Query Correction and Please Explan
Dear Experts
I have created a query to Sales Order ORDR and its Data from RDR1 and RDR1 and Connected it to Delievery ODLN. I want all the Sales Order irrespective of the Delievery is made or not. I some documents I am getting cartesian product. Please check the query and if can correct the mistake and Please do explain the your joining statement as the problem lies their.
Please find the query is below:
SELECT * FROM
ORDR T0 INNER JOIN RDR1 T1 ON T0.DocNum = T1.DocEntry
LEFT JOIN RDR2 T2 ON T0.DocEntry = T2.DocEntry
LEFT JOIN ODLN T3 ON T0.DocNum = T3.DocNum AND
T1.LineNum=T2.LineNum
Ill be grateful.
FaisalHi Faisal.......
Try this.....
SELECT * FROM
ODLN T0 LEFT JOIN RDR1 T1 ON T0.DocEntry = T1.TrgetEntry
LEFT JOIN RDR2 T2 ON T1.DocEntry = T2.DocEntry
Hope this will help you.....
Regards,
Rahul
Edited by: RAHUL MOUNDEKAR on Nov 26, 2010 2:03 PM -
Query Correction and Guidance Needed
Dear Experts
I am adding a query I have developed from three tables ORCT, RCT1 and JDT1. I wanted to get the reconciliation report for Bank Statement. ORCT is used to get the BP Name, RCT1 for check number and JDT1 to get the Debit and Credit fields. I have been successful only to out that transation for Cash are missing can you please correct the query if possible and guide me where I went wrong I will be greatly obliged. Below is the query
SELECT '1Icoming - Reconciled' as grp, T2.RefDate, T1.CheckNum, T0.CardName,
T2.Debit, T2.Credit
FROM ORCT T0, RCT1 T1, JDT1 T2
WHERE (T0.DocEntry = T1.DocNum AND
T0.TransId = T2.TransId AND
T2.Line_ID = T1.LineID) AND
T2.Account IN ('_SYS00000004973') AND
T2.ExtrMatch IN (1,2,3,4,5,6) AND
T2.RefDate BETWEEN '04-30-2010' AND {?To}Hi Faisal,
Try this query:
SELECT '1Icoming - Reconciled' as grp, T2.RefDate, T1.CheckNum,T0.[CheckSum] , T0.CardName, T0.CashSum ,T0.CashAcct,
T2.Debit, T2.Credit
FROM ORCT T0, RCT1 T1, JDT1 T2
WHERE (T0.DocEntry = T1.DocNum AND
T0.TransId = T2.TransId AND
T2.Line_ID = T1.LineID) AND
T2.Account IN ('_SYS00000004973') AND
T2.ExtrMatch IN (1,2,3,4,5,6) AND
(T2.RefDate >= [%1] and T2.RefDate <= [%2])
Thanks,
Neetu -
Opening & Closing Stock - Query Correction
Dear Experts,
Please find the below query, where I need IN quantity & values , OUT quantity& values should pick only from Standard Production Order , whereas it should not pick from special Production Order. Rest all in the same is sufficient for me.
Declare @FromDate Datetime
Declare @ToDate Datetime
Declare @ItmsGrpNam varchar(100)
select @FromDate = min(S0.Docdate) from dbo.OINM S0 where S0.Docdate >= '[%0]'
select @ToDate = max(S1.Docdate) from dbo.OINM s1 where S1.Docdate <='[%1]'
select @ItmsGrpNam = max(s2.ItmsGrpNam) from dbo.OITB S2 Where S2.ItmsGrpNam ='[%2]'
Select a.Itemcode, max(a.Dscription) as ItemName,
(Select i.InvntryUom from OITM i where i.ItemCode=a.Itemcode) as UOM,
sum(a.OpeningBalance) as OpeningBalance,
sum(a.OpeningValue) as OpeningValue,
sum(a.INq) as 'IN',
(select SUM(ISNULL(T100.TRANSVALUE,0)) from oinm T100 WHERE T100.ITEMCODE = A.ITEMCODE
AND T100.DOCDATE >= @FROMDATE
AND T100.DOCDATE <= @TODATE AND T100.INQTY <> 0) AS [IN Stock Value],
sum(a.OUT) as OUT,
(select SUM(ISNULL(T100.TRANSVALUE,0)) from oinm T100 WHERE T100.ITEMCODE = A.ITEMCODE
AND T100.DOCDATE >= @FROMDATE
AND T100.DOCDATE <= @TODATE AND T100.OUTQTY <> 0)*-1 AS [OUT Stock Value],
((sum(a.OpeningBalance) + sum(a.INq)) - Sum(a.OUT)) as Closing ,
(select SUM(T100.TRANSVALUE) from oinm T100 WHERE
T100.ITEMCODE = A.ITEMCODE AND T100.DOCDATE < @TODATE) AS [Closing Value Transaction],
(((sum(a.OpeningBalance) + sum(a.INq)) - Sum(a.OUT))*
ISNULL((SELECT CASE WHEN
X.PRICE = 0
THEN
(SELECT DISTINCT MAX(ISNULL(P.PRICE,0)) AS PRICE FROM ITM1 P WHERE PRICELIST = 1 )
ELSE
X.PRICE
END
FROM (SELECT
DISTINCT MAX(ISNULL(B.PRICE,0)) AS PRICE
FROM OITM T
LEFT JOIN PCH1 B ON T.ITEMCODE = B.ITEMCODE
INNER JOIN OPCH C ON B.DOCENTRY = C.DOCENTRY
WHERE B.DOCENTRY = (SELECT DISTINCT (MAX(D.DOCENTRY)) FROM OPCH D WHERE C.DOCENTRY = D.DOCENTRY
AND C.DOCDATE <= @ToDate )
AND A.ITEMCODE = T.ITEMCODE) X ),0))
--(Select i.LstEvlPric from OITM i where i.ItemCode=a.Itemcode))
as 'Closing Value',
(Select i.LastPurDat from OITM i where i.ItemCode=a.Itemcode) as 'Last Purchase Date',
--(Select i.LstEvlDate from OITM i where i.ItemCode=a.Itemcode) as 'Last Issue Date',
--(Select i.ItmsGrpCod from OITM i where i.ItemCode=a.Itemcode) as 'Group code',
(Select b.ItmsGrpNam from OITB b where b.ItmsGrpCod = I1.ItmsGrpCod) as 'Group Name'
from( Select N1.Itemcode, N1.Dscription, (sum(N1.inqty)-sum(n1.outqty))
as OpeningBalance,
(sum(N1.Transvalue))
as OpeningValue,
0 as INq, 0 as OUT From dbo.OINM N1 inner join OITM i on i.ItemCode = N1.ItemCode
inner join OITB b on b.ItmsGrpCod = i.ItmsGrpCod
Where N1.DocDate <@FromDate and b.ItmsGrpNam = @ItmsGrpNam
Group By N1.ItemCode,N1.Dscription
Union All
select N1.Itemcode, N1.Dscription, 0 as OpeningBalance,0 as OpeningValue,
sum(N1.inqty) , 0 as OUT From dbo.OINM N1 inner join OITM i on i.ItemCode = N1.ItemCode
inner join OITB b on b.ItmsGrpCod = i.ItmsGrpCod
Where N1.DocDate >= @FromDate and N1.DocDate <= @ToDate
and N1.Inqty >0 and b.ItmsGrpNam = @ItmsGrpNam
Group By N1.ItemCode,N1.Dscription
Union All
select N1.Itemcode, N1.Dscription, 0 as OpeningBalance,0 as OpeningValue, 0 , sum(N1.outqty) as OUT
From dbo.OINM N1 inner join OITM i on i.ItemCode = N1.ItemCode
inner join OITB b on b.ItmsGrpCod = i.ItmsGrpCod
Where N1.DocDate >= @FromDate and N1.Transtype != 67
and N1.DocDate <=@ToDate and N1.OutQty > 0 and b.ItmsGrpNam = @ItmsGrpNam
Group By N1.ItemCode,N1.Dscription) a, dbo.OITM I1 ,OITB b1
where a.ItemCode=I1.ItemCode
and I1.ItmsGrpCod = b1.ItmsGrpCod
Group By a.Itemcode ,I1.ItmsGrpCod , b1.ItmsGrpNam
Having sum(a.OpeningBalance) + sum(a.INq) + sum(a.OUT) > 0
Order By a.Itemcode
Thanks in Advance,
Bhoopathi.KHi,
Try this:
Declare @FromDate Datetime
Declare @ToDate Datetime
Declare @ItmsGrpNam varchar(100)
select @FromDate = min(S0.Docdate) from dbo.OINM S0 where S0.Docdate >= '[%0]'
select @ToDate = max(S1.Docdate) from dbo.OINM s1 where S1.Docdate <='[%1]'
select @ItmsGrpNam = max(s2.ItmsGrpNam) from dbo.OITB S2 Where S2.ItmsGrpNam ='[%2]'
Select a.Itemcode, max(a.Dscription) as ItemName,
(Select i.InvntryUom from OITM i where i.ItemCode=a.Itemcode) as UOM,
sum(a.OpeningBalance) as OpeningBalance,
sum(a.OpeningValue) as OpeningValue,
sum(a.INq) as 'IN',
(select SUM(ISNULL(T100.TRANSVALUE,0)) from oinm T100 WHERE T100.ITEMCODE = A.ITEMCODE
AND T100.DOCDATE >= @FROMDATE
AND T100.DOCDATE <= @TODATE AND T100.INQTY <> 0) AS [IN Stock Value],
sum(a.OUT) as OUT,
(select SUM(ISNULL(T100.TRANSVALUE,0)) from oinm T100 WHERE T100.ITEMCODE = A.ITEMCODE
AND T100.DOCDATE >= @FROMDATE
AND T100.DOCDATE <= @TODATE AND T100.OUTQTY <> 0)*-1 AS [OUT Stock Value],
((sum(a.OpeningBalance) + sum(a.INq)) - Sum(a.OUT)) as Closing ,
(select SUM(T100.TRANSVALUE) from oinm T100 WHERE
T100.ITEMCODE = A.ITEMCODE AND T100.DOCDATE < @TODATE) AS [Closing Value Transaction],
(((sum(a.OpeningBalance) + sum(a.INq)) - Sum(a.OUT))*
ISNULL((SELECT CASE WHEN
X.PRICE = 0
THEN
(SELECT DISTINCT MAX(ISNULL(P.PRICE,0)) AS PRICE FROM ITM1 P WHERE PRICELIST = 1 )
ELSE
X.PRICE
END
FROM (SELECT
DISTINCT MAX(ISNULL(B.PRICE,0)) AS PRICE
FROM OITM T
LEFT JOIN PCH1 B ON T.ITEMCODE = B.ITEMCODE
INNER JOIN OPCH C ON B.DOCENTRY = C.DOCENTRY
WHERE B.DOCENTRY = (SELECT DISTINCT (MAX(D.DOCENTRY)) FROM OPCH D WHERE C.DOCENTRY = D.DOCENTRY
AND C.DOCDATE <= @ToDate )
AND A.ITEMCODE = T.ITEMCODE) X ),0))
--(Select i.LstEvlPric from OITM i where i.ItemCode=a.Itemcode))
as 'Closing Value',
(Select i.LastPurDat from OITM i where i.ItemCode=a.Itemcode) as 'Last Purchase Date',
--(Select i.LstEvlDate from OITM i where i.ItemCode=a.Itemcode) as 'Last Issue Date',
--(Select i.ItmsGrpCod from OITM i where i.ItemCode=a.Itemcode) as 'Group code',
(Select b.ItmsGrpNam from OITB b where b.ItmsGrpCod = I1.ItmsGrpCod) as 'Group Name'
from( Select N1.Itemcode, N1.Dscription, (sum(N1.inqty)-sum(n1.outqty))
as OpeningBalance,
(sum(N1.Transvalue))
as OpeningValue,
0 as INq, 0 as OUT From dbo.OINM N1 inner join OITM i on i.ItemCode = N1.ItemCode
inner join OITB b on b.ItmsGrpCod = i.ItmsGrpCod
Where N1.DocDate <@FromDate and b.ItmsGrpNam = @ItmsGrpNam
Group By N1.ItemCode,N1.Dscription
Union All
select N1.Itemcode, N1.Dscription, 0 as OpeningBalance,0 as OpeningValue,
sum(N1.inqty) , 0 as OUT From dbo.OINM N1 inner join OITM i on i.ItemCode = N1.ItemCode
inner join OITB b on b.ItmsGrpCod = i.ItmsGrpCod
Where N1.DocDate >= @FromDate and N1.DocDate <= @ToDate
and N1.Inqty >0 and b.ItmsGrpNam = @ItmsGrpNam
Group By N1.ItemCode,N1.Dscription
Union All
select N1.Itemcode, N1.Dscription, 0 as OpeningBalance,0 as OpeningValue, 0 , sum(N1.outqty) as OUT
From dbo.OINM N1 inner join OITM i on i.ItemCode = N1.ItemCode
inner join OITB b on b.ItmsGrpCod = i.ItmsGrpCod left join OWOR t0 on t0.docentry = N1.[AppObjAbs]
Where N1.DocDate >= @FromDate and N1.Transtype != 67
and N1.DocDate <=@ToDate and N1.OutQty > 0 and b.ItmsGrpNam = @ItmsGrpNam and T0.[Type] = 's'
Group By N1.ItemCode,N1.Dscription) a, dbo.OITM I1 ,OITB b1
where a.ItemCode=I1.ItemCode
and I1.ItmsGrpCod = b1.ItmsGrpCod
Group By a.Itemcode ,I1.ItmsGrpCod , b1.ItmsGrpNam
Having sum(a.OpeningBalance) + sum(a.INq) + sum(a.OUT) > 0
Order By a.Itemcode
Thanks & Regards,
Nagarajan -
Isn't This SQL Query Correct?
Hi Everyone,
I was reading some tutorials about removing jobs. And i found out the query to be something like:
EXECUTE DBMS_JOB.REMOVE(2);
where 2 is the job number. I executed the same command and i get the error as "Invalid SQL Statement". Does this mean the tutorial is wrong? :(
The link to the tutorial is:
http://www.dbasupport.com/oracle/ora9i/jobqueue2.shtmlfrom where are you executing the job...??
exec(ute) is a sql plus command....you can use it only from sql plus...
All editors which allow sql plus commands will accept above command. Sql developer won't accept exec command. So you need to write a pl/sql block there like
begin
DBMS_JOB.REMOVE(12);
end;But from sql plus
EXECUTE DBMS_JOB.REMOVE(2); is enough.
Ravi Kumar -
Hi Guys
Can anyone tell me the select query is write for the following tables
equi,eqkt,iloa,imrg and imptt
regards
*EQUI
select equnr from equi into table T_equi
FOR ALL ENTRIES IN IT_DATA
where objnr = it_data-mpobj .
*EQKT
select eqktx into table T_eqkt
from eqkt
FOR ALL ENTRIES IN IT_DATA
where equnr = it_data-Equnr.
*ILOA
select eqfnr into table T_iloa
from iloa
FOR ALL ENTRIES IN IT_DATA
where iloan = it_data-iloan .
*IMPTT
*select mpobj into table T_imptt
*from imptt
*FOR ALL ENTRIES IN IT_DATA
*where IMPTT-mpobj = it_imptt-mpobj.
*IMRG
select idate recdv recdu into table T_imrg
from imrg
FOR ALL ENTRIES IN IT_DATA
imrg
where MPOBJ = it_data-MPOBJ AND
equnr = it_data-equnr AND
POINT = it_data-point.
loop at it_data into wa_data.
READ TABLE T_EQUI INTO wa_equi
WITH KEY objnr = WA_DATA-mpobj.
BINARY SEARCH.
IF SY-SUBRC = 0.
WA_DATA-OBJNR = T_EQUI-OBJNR.
ENDIF.
READ TABLE T_EQKT WITH KEY EQUNR = WA_DATA-EQUNR.
IF SY-SUBRC = 0.
WA_DATA-EQKTX = T_EQKT-EQKTX.
ENDIF.
READ TABLE T_ILOA WITH KEY ILOAN = WA_DATA-ILOAN.
IF SY-SUBRC = 0.
WA_DATA-ILOAN = T_ILOA-ILOAN.
ENDIF.
*READ TABLE T_IMPTT WITH KEY MPOBJ = WA_DATA-MPOBJ.
*IF SY-SUBRC = 0.
WA_DATA-EQUNR = T_IMPTT-MPOBJ
WA_DATA-OBJNR = T_EQUI-OBJNR.
*ENDIF.
READ TABLE T_IMRG WITH KEY OBJNR = WA_DATA-OBJNR.
IF SY-SUBRC = 0.
WA_DATA-EQUNR = T_IMRG-EQUNR .
ENDIF.
MODIFY IT_DATA_ FROM WA_DATA.
*SORT i_data BY idate recdv ascending.
*Read table i_data into wa_data index 1.
LOOP AT i_data INTO wa_data.
CLEAR: wa_data.
READ TABLE i_data into wa_data
WITH KEY equnr = wa_data-equnr.Travel expense are integrated to payroll via wage types.
Hence you need to check what is the expense type mapping to wage types, then you can see in pc_payresult. -
How to execute this query correctly?
Hi sir,
i am using one query which i converted from sql to oracle but getting error.
Error(4,3): PLS-00428: an INTO clause is expected in this SELECT statement
here is my query:
SELECT distinct pa.id Code, pa.Empcode Emp_ID, E.Emp_FirstName || ' ' || E.Emp_LastName Emp_Name, pa.WorkDate Date1 , pa.InPunch In_Punch , pa.OutPunch Out_Punch , pa.approve , ls.Leave_Status_text StatusText , NVL(pt.punchtype, 'Updated') punchtype FROM PunchForApproval pa JOIN Employee E ON e.Emp_ID = pa.Empcode LEFT JOIN Leave_status ls ON ls.Leave_Status_id = pa.approve LEFT JOIN punchtype pt ON pt.id = pa.STATUS
WHERE E.Emp_ID IN ( SELECT Emp_id FROM employees)ORDER BY pa.id DESC ;
thanksThis is the forum for the SQL Developer tool, Not for general SQL/PLSQL questions. Please close this thread and repost in the PL/SQL forum.
PL/SQL doesn't work like TSQL. If you have a query within a PL/SQL block, you must fetch it INTO something ( a record or a set of scalar variables ) for processing. -
SQL query to correct the corrupted data
Hi All,
I got strucked up with a query correcting the corrupted records.
CREATE TABLE EX1
EMPID INTEGER,
DW_EFF_DT DATE,
DW_EXPR_DT DATE
INSERT INTO EX1 VALUES(1,'04-MAR-1998','13-MAR-1999');
INSERT INTO EX1 VALUES(1,'14-MAR-1999','02-MAY-2000');
INSERT INTO EX1 VALUES(1,'03-MAY-2000','01-MAY-2013');
INSERT INTO EX1 VALUES(1,'02-MAY-2013','31-DEC-9999');
I have empid with other attributes,we are maintaing history.There is some data which is corrupted and we need to correct it.
DW_EFF_DT which is less than '01-FEB-2005' should be made by default '31-JAN-2005'
Again the data should be corrected and my output should be like the below
EMPNO DW_EFF_DT DW_EXPR_DT
1 2005-01-27 2005-01-28
1 2005-01-29 2005-01-30
1 2005-01-31 2013-05-01
1 2013-05-02 9999-12-31
I used the lead and lag function,but it is applied sequentially.
How I can get the dates subtratcing by 1 for each and every alternative row.
I tried the below query and able to achive half of it.
SELECT A.* ,COALESCE(LEAD(NEW_DW_EFF,1) OVER(ORDER BY NEW_DW_EFF) -1,TO_DATE('31-DEC-9999','DD-MON-YYYY')) AS NEW_DW_EXPR_DT
FROM
SELECT ID,
DW_EFF_DT,
DW_EXPR_DT,
CASE WHEN DW_EFF_DT<TO_DATE('01-FEB-2005','DD-MON-YYYY') THEN TO_DATE('31-JAN-2005','DD-MON-YYYY') ELSE DW_EFF_DT END AS NEW_DW_EFF
FROM EX1
)A
ID DW_EFF_DT DW_EXPR_DT NEW_DW_EFF NEW_DW_EXPR_DT
1 04-MAR-98 13-MAR-99 31-JAN-05 30-JAN-05
1 14-MAR-99 02-MAY-00 31-JAN-05 30-JAN-05
1 03-MAY-00 01-MAY-13 31-JAN-05 01-MAY-13
1 02-MAY-13 31-DEC-99 02-MAY-13 31-DEC-99
Please help me in this regard.i am still trying it.
Thanks in advance,
KVBKVB wrote:
EMPNO DW_EFF_DT DW_EXPR_DT
1 2005-01-27 2005-01-28
1 2005-01-29 2005-01-30
1 2005-01-31 2013-05-01
1 2013-05-02 9999-12-31
Actually the last record is the active record.
Th 3rd record effectiuve date is adjusted because the dateis less than 2005-02-01. So that we adjusted to 2005-01-31,
The 2nd record expiry date will be adjusted to 3rd record effective date-1,
Now the 2nd record effective will be adjusted to 2nd record expiry date-1 and so on..until the first record.
Actually I could not explain much better in business point of view like why they do this.Technically we need to achive this through SQL.
CheersOkay, that makes more sense, thanks :)
Probably not the prettiest ... but should work (you may need to tweak it a bit)
ME_TUBBZ? select
2 empid
3 , to_date('2005-02-01','yyyy-mm-dd') - ( 2* rn) + 1 as new_eff_date
4 , case
5 when rn = 1
6 then
7 dw_expr_dt
8 else
9 to_date('2005-02-01','yyyy-mm-dd') - (2 * (rn - 1))
10 end
11 as new_exp_date
12 , dw_eff_dt
13 , dw_expr_dt
14 from
15 (
16 select
17 empid
18 , dw_eff_dt
19 , dw_expr_dt
20 , row_number() over (partition by empid order by dw_eff_dt desc) as rn
21 from ex1
22 where dw_eff_dt < to_date('2005-02-01','yyyy-mm-dd')
23 )
24 order by dw_eff_dt asc
25 /
EMPID NEW_EFF_DATE NEW_EXP_DATE DW_EFF_DT DW_EXPR_DT
1 27-JAN-2005 00 00:00 28-JAN-2005 00 00:00 04-MAR-1998 00 00:00 13-MAR-1999 00 00:00
1 29-JAN-2005 00 00:00 30-JAN-2005 00 00:00 14-MAR-1999 00 00:00 02-MAY-2000 00 00:00
1 31-JAN-2005 00 00:00 01-MAY-2013 00 00:00 03-MAY-2000 00 00:00 01-MAY-2013 00 00:00
3 rows selected.
Elapsed: 00:00:00.01
ME_TUBBZ? Cheers, -
Query to select values greater than, where AS clause is used
Oracle 10g
Requesting your help in writing the query correctly.
I have the following 2 tables. The AddProjectPhase and AddProject tables. It is many to many relationship. Each project can have a predefined set of 4 different phases under it. Each phase has a start date and an end date. I am writing a report to get the phases which have a duration greater than, for example, 3 months.
The query below is working fine to just display the list of all the phases along with the duration of each phase. I am not able to modify it to select the phases which have a duration, for example, 3 or more months.
CREATE TABLE "ADDPROJECT"
( "VERSIONNO" NUMBER(*,0),
"PROJID" VARCHAR2(20),
"PROJNAME" VARCHAR2(60),
"PROJSTARTDATE" DATE,
"PROJSTATUS" VARCHAR2(20),
"PROJENDDATE" DATE,
"PROJENDTYPE" VARCHAR2(20),
"PROJENDREASON" VARCHAR2(1000),
"UCPROJECTMANAGER" VARCHAR2(20),
"FROMDATE" DATE,
"TODATE" DATE,
"SRCHFIELD" VARCHAR2(20),
"OPERATOR" VARCHAR2(20),
"PARENTPROJID" VARCHAR2(20),
"PROJHIDDENDATE" VARCHAR2(20),
CONSTRAINT "PK_B36" PRIMARY KEY ("PROJID", "PROJHIDDENDATE") ENABLE
CREATE TABLE "ADDPROJECTPHASE"
( "VERSIONNO" NUMBER(*,0),
"PROJPHASEID" NUMBER(9,0),
"PHASESTARTDATE" DATE,
"PHASEENDDATE" DATE,
"RRDATE" DATE,
"PHASENAME" VARCHAR2(30),
"PROJPHASESTATUS" VARCHAR2(20),
"PROJID" VARCHAR2(20),
"OPERATOR" VARCHAR2(20),
"FROMDATE" DATE,
"TODATE" DATE,
"SRCHFIELD" VARCHAR2(20),
"REVIEWCOMMENTS" VARCHAR2(1000),
"PROJHIDDENDATE" VARCHAR2(20),
"ISUEVALUATION" NUMBER(1,0),
"SOLUTIONINGTEAMINVOLVEMENT" NUMBER(1,0),
"ISUNAME" VARCHAR2(20),
CONSTRAINT "PK_A63" PRIMARY KEY ("PROJPHASEID") ENABLE
)Below is the query to display the list of all the phases along with the duration of each phase which is working fine.
SELECT pp.phaseName "phasename",
pp.phaseStartDate "phaseStartDate",
pp.phaseEndDate "phaseEndDate",
pp.projPhaseStatus "projPhaseStatus",
ap.projID "projID",
ap.projName "projName",
ap.projHiddenDate "projHiddenDate",
ap.projStartDate "projStartDate",
CASE
WHEN pp.phaseEndDate IS NOT NULL
THEN MONTHS_BETWEEN(1+pp.phaseEndDate,pp.phaseStartDate)
WHEN pp.phaseEndDate IS NULL
THEN MONTHS_BETWEEN(1+sysDate,pp.phaseStartDate)
ELSE null
END "phaseMonths"
FROM AddProjectPhase pp, AddProject ap
WHERE ap.projID = pp.projID
AND ap.projHiddenDate = pp.projHiddenDate
ORDER BY ap.projIDHowever the modified query shown below to select all the phases greater than, for example, 3 months, is resulting in
ORA-00904: "PHASEMONTHS": invalid identifier SELECT pp.phaseName, pp.phaseStartDate, pp.phaseEndDate
FROM AddProjectPhase pp, AddProject ap
WHERE ap.projID = pp.projID
AND ap.projHiddenDate = pp.projHiddenDate
AND PhaseMonths IN
(SELECT
(CASE
WHEN pp.phaseEndDate IS NOT NULL
THEN MONTHS_BETWEEN(1+pp.phaseEndDate,pp.phaseStartDate)
WHEN pp.phaseEndDate IS NULL
THEN MONTHS_BETWEEN(1+sysDate,pp.phaseStartDate)
ELSE null
END) AS PhaseMonths
FROM AddProjectPhase pp, AddProject ap
WHERE ap.projID = pp.projID
AND ap.projHiddenDate = pp.projHiddenDate)
ORDER BY ap.projIDLooking for this?
select *
from (
SELECT pp.phaseName "phasename"
, pp.phaseStartDate "phaseStartDate"
, pp.phaseEndDate "phaseEndDate"
, pp.projPhaseStatus "projPhaseStatus"
, ap.projID "projID"
, ap.projName "projName"
, ap.projHiddenDate "projHiddenDate"
, ap.projStartDate "projStartDate"
, CASE WHEN pp.phaseEndDate IS NOT NULL THEN MONTHS_BETWEEN(1+pp.phaseEndDate,pp.phaseStartDate)
WHEN pp.phaseEndDate IS NULL THEN MONTHS_BETWEEN(1+sysDate,pp.phaseStartDate)
ELSE null
END "phaseMonths"
FROM AddProjectPhase pp, AddProject ap
WHERE ap.projID = pp.projID
AND ap.projHiddenDate = pp.projHiddenDate
ORDER
BY ap.projID
where "phaseMonths" >= 3 -
I'm having trouble with an SQL query. I've created a simple logon page wherein a user will enter their user name and password. The program will look in an Access database for the user name, sort it by Date/Time modified, and check to see if their password matches the most recent password. Unfortunately, the query returns no results. I'm absolutely certain that I'm doing the query correctly (I've imported it directly from my old VB6 code). Something simple is eluding me. Any help would be appreciated.
private void LogOn() {
//make sure that the user name/password is valid, then load the main menu
try {
//open the database connection
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:LawOffice2000", "", "");
Statement select = con.createStatement();
String strTemp = "Select * From EMPLOYEES Where INITIALS = '" + txtUserName.getText() + "' Order By DATE Desc, TIME Desc";
ResultSet result = select.executeQuery(strTemp);
while(result.next()) {
if (txtPassword.getPassword().toString() == result.getString("Password")) {
MenuMain.main();
else {
System.out.println("Password Bad");
System.out.println(txtUserName.getText());
System.out.println(result.getString("Password"));
break; //exit loop
//close the connection
con.close(); }
catch (Exception e) {
System.out.println("LawOfficeSuite_LogOn: " + e);
return; }
}The problem is here: "txtPassword.getPassword().toString() == result.getString("Password"))"
Don't confuse String's equals() method with the equality operator '=='. The == operator checks that two references refer to the same object. If you want to compare the contents of Strings (whether two strings contain the same characters), use equals(), e.g. if (str1.equals(str2))...
Example:String s1 = "foo";
String s2 = new String("foo");
System.out.println("s1 == s2: " + (s1 == s2)); // false
System.out.println("s1.equals(s2): " + (s1.equals(s2))); // trueFor more information, check out Comparison operators: equals() versus == -
Amounts not displayed correctly in reporting
Hello,
We are facing a problem with data displayed in a created workbook. Amounts are multiplied by 100000.
We have loaded via file into BPC NW, and the information that is stored in the cube is 1.00000 (with 5 decimals), but what is displayed in the report 10,000.00 u2013 so it is reading the information as it is in the cube and putting two decimal places, which is not correct.
We have been checking in the Application Set and the Application parameters, but could not any related parameter to set this property.
I have been looking note 1231909, but does not apply to our case; our flat file does not contain thousands separators.
Could someone help with this issue?
Thanks&Kind regards,
BegoniaHI,
Not sure if I got your query correctly. But in general when you load an amount lets say 1500 from a flat file, the format in which this 1500 gets store in the cube is 1.500 (in the cube the decimal digits appear after a 'comma' ) ... And in your report in BPC this same value appears as 1,500 ... I think the decimal places can be removed from the workbook by formating the cell to not show the decimal values.
Hope this helps.
Thanks,
Prasanth. -
Query regarding memory upgrade
I have k8mm-v (MS 7142 v1.x) Micro ATX mobo with chipset k8m800-ce and VT8237
memory module required by the system: 184 pin unbuffererd ddr266/333/400 DDR SDRAM and can support upto 2 gb (this is as per motherboard manual)
My questions:
1. whether I can upgrade system memory with ddr1 1gb ram
2. do ddr sdram and ddr1 one and same thing........
3. Now a days in india 512 mb ddr ram are costly and i want to know if there is any other way and i can upgrade my system partially or fully (if so what should i upgrade like mobo etc........) please do help me.
4. I came across HCL ddr1 ram which seems to be less costly ................i had feeling that they would not fit onto my ram sockets (on motherboard) ..........I want to know if my hunch is real or i am just bit too nervous ...............and whether can I put HCL ram on to my system............please advise..............
your help would be greatly appreciated...............thanks....... .......in advance...............Quote from: zsde on 29-May-10, 16:17:32
This needs to be moved to an appropriate section in the forum by one of the moderators.
You would be indeed lucky to still find dealers that sell DDR400. At the same time you may have noticed that the prices for this RAM is way out of line with the current market price of DDR2 and DDR3. DDR3 is now becoming the mainstream standard and it would probably be appropriate to consider a change to this standard. If however you are happy with your set up and need more memory, then please consult the memory support list here : http://www.msi.com/uploads/test_report/TR10_173.pdf
If your mentioned HCL brand conforms to JEDEC standard, then there is no reason it should not work.
Suggest you do some reading on the JEDEC standard here: http://download.micron.com/pdf/misc/JEDEC79R2.pdf
It is always recommended that you use two identical mem modules in the two slots on your board, i.e. do not mix mem module size or mem modules with differing SPD values.
Your board does not support 2Gb modules. Your board supports 2Gb in total, i.e. 2 X 1Gb modules
I trust you will find more members giving you alternative solutions and recommendations.
I would like to be more specific, the "HCL ram" that I was talking about. Well, it happens to be name of company { "HCL Infosystems Ltd." (http://www.hcl.in/) } which produces assembled computer system and they also produce RAMs and did not meant in terms of HCL compatibility list that Microsoft talks regarding hardware compatibility (I am soo sorry, I did not correctly posted the query correctly)
I am unable to find whether they make RAM according to JEDEC standards.............
Please can any HCL guy ..................give me this clue to what standard they follow in making DDR 1 RAM
and thank you all for your kindness in providing heap of information..............thank you again and again ........... -
Hi -
I am having trouble selecting records through a view object's service interface based upon specifying a date+time in the query.
I have a legacy table that has, among other fields, a DATE field. I create a view object on the table with a query (no entity object) and generate a service interface for the view. The web service interface works great for selecting on the non-date fields, e.g.:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body xmlns:ns1="/rt/model/common/types/">
<ns1:findContact>
<ns1:findCriteria xmlns:ns2="http://xmlns.oracle.com/adf/svc/types/">
<ns2:filter>
<ns2:group>
<ns2:item>
<ns2:attribute>ContactName</ns2:attribute>
<ns2:operator>=</ns2:operator>
<ns2:value>bobishisname</ns2:value>
</ns2:item>
</ns2:group>
</ns2:filter>
<ns2:findAttribute>ContactTime</ns2:findAttribute>
</ns1:findCriteria>
</ns1:findContact>
</soap:Body>
</soap:Envelope>
successfully returns the response data:
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Header/>
<env:Body>
<ns0:findLastCustomerContactResponse xmlns:ns0="/rt/model/common/types/">
<ns2:result xmlns:ns2="/rt/model/common/types/" xmlns:ns1="/rt/model/common/"
xmlns:ns0="http://xmlns.oracle.com/adf/svc/types/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:ContactSDO">
<ns1:ContactTime>2012-02-14T14:59:02.0-08:00</ns1:ContactTime>
</ns2:result>
</ns0:findContactResponse>
</env:Body>
</env:Envelope>
However, when I add the item to restrict the ContactTime, the time component is dropped, and only the date is used in the filter.
For example, this request payload does not return a result (ContactTime greater than 12pm on 2012-02-14):
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body xmlns:ns1="/rt/model/common/types/">
<ns1:findContact>
<ns1:findCriteria xmlns:ns2="http://xmlns.oracle.com/adf/svc/types/">
<ns2:filter>
<ns2:group>
<ns2:item>
<ns2:attribute>ContactTime</ns2:attribute>
<ns2:operator>></ns2:operator>
<ns2:value>2012-02-14T12:00:00.0-08:00</ns2:value>
</ns2:item>
</ns2:group>
</ns2:filter>
<ns2:findAttribute>ContactName</ns2:findAttribute>
</ns1:findCriteria>
</ns1:findContact>
</soap:Body>
</soap:Envelope>
However, this request payload (ContactTime greater than 2012-02-13) does:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body xmlns:ns1="/rt/model/common/types/">
<ns1:findContact>
<ns1:findCriteria xmlns:ns2="http://xmlns.oracle.com/adf/svc/types/">
<ns2:filter>
<ns2:group>
<ns2:item>
<ns2:attribute>ContactTime</ns2:attribute>
<ns2:operator>></ns2:operator>
<ns2:value>2012-02-13T12:00:00.0-08:00</ns2:value>
</ns2:item>
</ns2:group>
</ns2:filter>
<ns2:findAttribute>ContactName</ns2:findAttribute>
</ns1:findCriteria>
</ns1:findContact>
</soap:Body>
</soap:Envelope>
returns the record:
<ns1:ContactName>bobishisname</ns1:ContactName>
In the view object, I can set the attribute type on the ContactTime field to Timestamp, but it does not affect the behavior. I cannot modify the underlying table to change from DATE to TIMESTAMP.
How do I set up the view object so that the service interface correctly passes the time component to the database and execute the query correctly?The select query is for fetching entry sheet number is:
select ebeln belnr bwart bewtp menge xblnr lfbnr mwskz shkzg srvpos packno from ekbe
into corresponding fields of table it_ekbe
for all entries in it_ekko
where belnr in s_belnr
and lfbnr in s_lfbnr
and ebeln = it_ekko-ebeln
and bwart = '101'
and bewtp eq 'E'. "for service acceptance no. (GR no.)
Here I have taken lfbnr as entry sheet number.
Maybe you are looking for
-
Dreamweaver design view doesn't show the bottom part of a long div
Hi! I'm doing a very graphics oriented site, which basically requires me to use a large jpg as a background image and placing text areas against this background using absolute positioning. My problem is that Dreamweaver doesn't show me the bottom
-
Screen enhancement of vl71 and ms66
Hi All, I am facing a requirement of adding a new selection-option on the screen of vl71 and ms66. Is it possible to do that coz they are standard programs or I have to copy them into a new customizing program. Thanks.
-
My question is this: If I do as you suggest in the General Tab of Preferences - see below - how do I get all the other tabs back if only the last one shows? If they are hidden, I need to know how to access them. Your directions which I need help with
-
Dreamweaver CC 2014 stucks when saving a page ... help
Hi, Please help me out. What is wrong? I work on a Mac OS X 10.9.5 After the update when saving a html or dwt page in Dreamweaver 2014 CC Dreamweaver stucks. It just keeps on waiting. I already have reinstalled the software, restarted my Mac twice an
-
On my child's Ipod 4 generation, we had put in the passcode wrong and the Ipod 4 generation has disabled to a length were it nows says "Connect to Itunes". We were wondering what that means.