Modify Query with POR1
I have a query that works fine......but i need add by item the sum of purcharse order (PO) in a same query....another column.
I try for a while but i can not make it work.....
The query give me sum per month of sales (in queantity) by item, then sum of qty in last 6 months, 3 months,etc.
Anyone can helpme with this?
this is the query:
select ItemCode, ItemName, ItmsGrpNam,
SUM(Jan) As Jan, SUM(Feb) As Feb, SUM(Mar) As Mar, SUM(Apr) As Apr, SUM(May) As May,SUM(Jun) As Jun,SUM(Jul) As Jul,SUM(Aug) As Aug,SUM(Sep) As Sep,SUM(Oct) As Oct,SUM(Nov) As Nov,SUM(Dec) As Dec,
(SUM(Jan6M)+SUM(Feb6M)+SUM(Mar6M)+SUM(Apr6M)+SUM(May6M)+SUM(Jun6M)+ SUM(Jul6M)+SUM(Aug6M)+SUM(Sep6M)+SUM(Oct6M)+SUM(Nov6M)+SUM(Dec6M)) As 'Vtas6M',
((SUM(Jan6M)+SUM(Feb6M)+SUM(Mar6M)+SUM(Apr6M)+SUM(May6M)+SUM(Jun6M)+ SUM(Jul6M)+SUM(Aug6M)+SUM(Sep6M)+SUM(Oct6M)+SUM(Nov6M)+SUM(Dec6M)))/6 As PromVtas6M,
(SUM(Jan3M)+SUM(Feb3M)+SUM(Mar3M)+SUM(Apr3M)+SUM(May3M)+SUM(Jun3M)+ SUM(Jul3M)+SUM(Aug3M)+SUM(Sep3M)+SUM(Oct3M)+SUM(Nov3M)+SUM(Dec3M)) As 'Vtas3M',
((SUM(Jan3M)+SUM(Feb3M)+SUM(Mar3M)+SUM(Apr3M)+SUM(May3M)+SUM(Jun3M)+ SUM(Jul3M)+SUM(Aug3M)+SUM(Sep3M)+SUM(Oct3M)+SUM(Nov3M)+SUM(Dec3M)))/3 As Promvtas3M,OnHand AS StockGlobal,
((SUM(Jan6M)+SUM(Feb6M)+SUM(Mar6M)+SUM(Apr6M)+SUM(May6M)+SUM(Jun6M)+ SUM(Jul6M)+SUM(Aug6M)+SUM(Sep6M)+SUM(Oct6M)+SUM(Nov6M)+SUM(Dec6M))/180) AS 'PromDiario6M',
CASE WHEN ItmsGrpNam = 'AC CINTAS' and OnHand <= (((SUM(Jan6M)+SUM(Feb6M)+SUM(Mar6M)+SUM(Apr6M)+SUM(May6M)+SUM(Jun6M)+ SUM(Jul6M)+SUM(Aug6M)+SUM(Sep6M)+SUM(Oct6M)+SUM(Nov6M)+SUM(Dec6M))/180)*50) then 'PEDIR'
WHEN ItmsGrpNam = 'AC ADHESIVOS' and OnHand <= (((SUM(Jan6M)+SUM(Feb6M)+SUM(Mar6M)+SUM(Apr6M)+SUM(May6M)+SUM(Jun6M)+ SUM(Jul6M)+SUM(Aug6M)+SUM(Sep6M)+SUM(Oct6M)+SUM(Nov6M)+SUM(Dec6M))/180)*50) then 'PEDIR'
WHEN ItmsGrpNam = 'CN POLISOCIANURATO' and OnHand <= (((SUM(Jan6M)+SUM(Feb6M)+SUM(Mar6M)+SUM(Apr6M)+SUM(May6M)+SUM(Jun6M)+ SUM(Jul6M)+SUM(Aug6M)+SUM(Sep6M)+SUM(Oct6M)+SUM(Nov6M)+SUM(Dec6M))/180)*25) then 'PEDIR'
WHEN ItmsGrpNam = 'HV NOMAGUARD' and OnHand <= (((SUM(Jan6M)+SUM(Feb6M)+SUM(Mar6M)+SUM(Apr6M)+SUM(May6M)+SUM(Jun6M)+ SUM(Jul6M)+SUM(Aug6M)+SUM(Sep6M)+SUM(Oct6M)+SUM(Nov6M)+SUM(Dec6M))/180)*28) then 'PEDIR' END AS Satus
FROM
(select ItemCode, ItemName, ItmsGrpNam,
(CASE WHEN Month = 1 THEN Quantity ELSE 0 END) As Jan,
(CASE WHEN Month = 2 THEN Quantity ELSE 0 END) As Feb,
(CASE WHEN Month = 3 THEN Quantity ELSE 0 END) As Mar,
(CASE WHEN Month = 4 THEN Quantity ELSE 0 END) As Apr,
(CASE WHEN Month = 5 THEN Quantity ELSE 0 END) As May,
(CASE WHEN Month = 6 THEN Quantity ELSE 0 END) As Jun,
(CASE WHEN Month = 7 THEN Quantity ELSE 0 END) As Jul,
(CASE WHEN Month = 8 THEN Quantity ELSE 0 END) As Aug,
(CASE WHEN Month = 9 THEN Quantity ELSE 0 END) As Sep,
(CASE WHEN Month = 10 THEN Quantity ELSE 0 END) As Oct,
(CASE WHEN Month = 11 THEN Quantity ELSE 0 END) As Nov,
(CASE WHEN Month = 12 THEN Quantity ELSE 0 END) As Dec,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 1 THEN Quantity ELSE 0 END) As Jan6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 2 THEN Quantity ELSE 0 END) As Feb6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 3 THEN Quantity ELSE 0 END) As Mar6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 4 THEN Quantity ELSE 0 END) As Apr6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 5 THEN Quantity ELSE 0 END) As May6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 6 THEN Quantity ELSE 0 END) As Jun6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 7 THEN Quantity ELSE 0 END) As Jul6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 8 THEN Quantity ELSE 0 END) As Aug6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 9 THEN Quantity ELSE 0 END) As Sep6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 10 THEN Quantity ELSE 0 END) As Oct6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 11 THEN Quantity ELSE 0 END) As Nov6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 12 THEN Quantity ELSE 0 END) As Dec6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 1 THEN Quantity ELSE 0 END) As Jan3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 2 THEN Quantity ELSE 0 END) As Feb3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 3 THEN Quantity ELSE 0 END) As Mar3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 4 THEN Quantity ELSE 0 END) As Apr3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 5 THEN Quantity ELSE 0 END) As May3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 6 THEN Quantity ELSE 0 END) As Jun3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 7 THEN Quantity ELSE 0 END) As Jul3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 8 THEN Quantity ELSE 0 END) As Aug3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 9 THEN Quantity ELSE 0 END) As Sep3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 10 THEN Quantity ELSE 0 END) As Oct3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 11 THEN Quantity ELSE 0 END) As Nov3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 12 THEN Quantity ELSE 0 END) As Dec3M,OnHand
FROM
( SELECT DISTINCT T0.ItemCode, T0.OnHand, T0.ItemName, T1.ItmsGrpNam, T2.unitMsr, T2.Quantity, T2.LineTotal,MONTH(T3.DocDate) As Month,T3.DocDate
FROM OITM T0 INNER JOIN OITB T1 ON T0.ItmsGrpCod = T1.ItmsGrpCod
INNER JOIN INV1 T2 ON T0.ItemCode = T2.ItemCode
INNER JOIN OINV T3 ON T2.DocEntry = T3.DocEntry
WHERE T3.Docdate >='20100101' AND T3.Docdate <= '20101231' AND T2.TargetType <> '14' ) source ) VIEW2
Group by VIEW2.ItemCode, VIEW2.OnHand,VIEW2.ItemName, VIEW2.ItmsGrpNam
Carlos,
Try this Code.
select View2.ItemCode, ItemName, ItmsGrpNam,
SUM(Jan) As Jan, SUM(Feb) As Feb, SUM(Mar) As Mar,
SUM(Apr) As Apr, SUM(May) As May,SUM(Jun) As Jun,
SUM(Jul) As Jul,SUM(Aug) As Aug,SUM(Sep) As Sep,
SUM(Oct) As Oct,SUM(Nov) As Nov,SUM(Dec) As Dec,
(SUM(Jan6M)SUM(Feb6M)SUM(Mar6M)SUM(Apr6M)SUM(May6M)SUM(Jun6M)
SUM(Jul6M)SUM(Aug6M)SUM(Sep6M)SUM(Oct6M)SUM(Nov6M)+SUM(Dec6M)) As 'Vtas6M',
((SUM(Jan6M)SUM(Feb6M)SUM(Mar6M)SUM(Apr6M)SUM(May6M)SUM(Jun6M)
SUM(Jul6M)SUM(Aug6M)SUM(Sep6M)SUM(Oct6M)SUM(Nov6M)+SUM(Dec6M)))/6 As PromVtas6M,
(SUM(Jan3M)SUM(Feb3M)SUM(Mar3M)SUM(Apr3M)SUM(May3M)SUM(Jun3M)
SUM(Jul3M)SUM(Aug3M)SUM(Sep3M)SUM(Oct3M)SUM(Nov3M)+SUM(Dec3M)) As 'Vtas3M',
((SUM(Jan3M)SUM(Feb3M)SUM(Mar3M)SUM(Apr3M)SUM(May3M)SUM(Jun3M)
SUM(Jul3M)SUM(Aug3M)SUM(Sep3M)SUM(Oct3M)SUM(Nov3M)+SUM(Dec3M)))/3 As Promvtas3M,
OnHand AS StockGlobal,
((SUM(Jan6M)SUM(Feb6M)SUM(Mar6M)SUM(Apr6M)SUM(May6M)SUM(Jun6M)
SUM(Jul6M)SUM(Aug6M)SUM(Sep6M)SUM(Oct6M)SUM(Nov6M)+SUM(Dec6M))/180) AS 'PromDiario6M',
CASE WHEN ItmsGrpNam = 'AC CINTAS'
and OnHand <= (((SUM(Jan6M)SUM(Feb6M)SUM(Mar6M)SUM(Apr6M)SUM(May6M)SUM(Jun6M)
SUM(Jul6M)SUM(Aug6M)SUM(Sep6M)SUM(Oct6M)SUM(Nov6M)+SUM(Dec6M))/180)*50) then 'PEDIR'
WHEN ItmsGrpNam = 'AC ADHESIVOS'
and OnHand <= (((SUM(Jan6M)SUM(Feb6M)SUM(Mar6M)SUM(Apr6M)SUM(May6M)SUM(Jun6M)
SUM(Jul6M)SUM(Aug6M)SUM(Sep6M)SUM(Oct6M)SUM(Nov6M)+SUM(Dec6M))/180)*50) then 'PEDIR'
WHEN ItmsGrpNam = 'CN POLISOCIANURATO'
and OnHand <= (((SUM(Jan6M)SUM(Feb6M)SUM(Mar6M)SUM(Apr6M)SUM(May6M)SUM(Jun6M)
SUM(Jul6M)SUM(Aug6M)SUM(Sep6M)SUM(Oct6M)SUM(Nov6M)+SUM(Dec6M))/180)*25) then 'PEDIR'
WHEN ItmsGrpNam = 'HV NOMAGUARD'
and OnHand <= (((SUM(Jan6M)SUM(Feb6M)SUM(Mar6M)SUM(Apr6M)SUM(May6M)SUM(Jun6M)
SUM(Jul6M)SUM(Aug6M)SUM(Sep6M)SUM(Oct6M)SUM(Nov6M)+SUM(Dec6M))/180)*28) then 'PEDIR' END AS Satus,
ISNULL(POItemSum.POSum,0.000000) as POSum
FROM (
select ItemCode, ItemName, ItmsGrpNam,
(CASE WHEN Month = 1 THEN Quantity ELSE 0 END) As Jan,
(CASE WHEN Month = 2 THEN Quantity ELSE 0 END) As Feb,
(CASE WHEN Month = 3 THEN Quantity ELSE 0 END) As Mar,
(CASE WHEN Month = 4 THEN Quantity ELSE 0 END) As Apr,
(CASE WHEN Month = 5 THEN Quantity ELSE 0 END) As May,
(CASE WHEN Month = 6 THEN Quantity ELSE 0 END) As Jun,
(CASE WHEN Month = 7 THEN Quantity ELSE 0 END) As Jul,
(CASE WHEN Month = 8 THEN Quantity ELSE 0 END) As Aug,
(CASE WHEN Month = 9 THEN Quantity ELSE 0 END) As Sep,
(CASE WHEN Month = 10 THEN Quantity ELSE 0 END) As Oct,
(CASE WHEN Month = 11 THEN Quantity ELSE 0 END) As Nov,
(CASE WHEN Month = 12 THEN Quantity ELSE 0 END) As Dec,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 1 THEN Quantity ELSE 0 END) As Jan6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 2 THEN Quantity ELSE 0 END) As Feb6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 3 THEN Quantity ELSE 0 END) As Mar6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 4 THEN Quantity ELSE 0 END) As Apr6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 5 THEN Quantity ELSE 0 END) As May6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 6 THEN Quantity ELSE 0 END) As Jun6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 7 THEN Quantity ELSE 0 END) As Jul6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 8 THEN Quantity ELSE 0 END) As Aug6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 9 THEN Quantity ELSE 0 END) As Sep6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 10 THEN Quantity ELSE 0 END) As Oct6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 11 THEN Quantity ELSE 0 END) As Nov6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 180) and Month = 12 THEN Quantity ELSE 0 END) As Dec6M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 1 THEN Quantity ELSE 0 END) As Jan3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 2 THEN Quantity ELSE 0 END) As Feb3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 3 THEN Quantity ELSE 0 END) As Mar3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 4 THEN Quantity ELSE 0 END) As Apr3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 5 THEN Quantity ELSE 0 END) As May3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 6 THEN Quantity ELSE 0 END) As Jun3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 7 THEN Quantity ELSE 0 END) As Jul3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 8 THEN Quantity ELSE 0 END) As Aug3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 9 THEN Quantity ELSE 0 END) As Sep3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 10 THEN Quantity ELSE 0 END) As Oct3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 11 THEN Quantity ELSE 0 END) As Nov3M,
(CASE WHEN DocDate >= (CURRENT_TIMESTAMP - 90) and Month = 12 THEN Quantity ELSE 0 END) As Dec3M,
OnHand
FROM (
SELECT DISTINCT T0.ItemCode, T0.OnHand, T0.ItemName, T1.ItmsGrpNam, T2.unitMsr,
T2.Quantity, T2.LineTotal,MONTH(T3.DocDate) As Month,T3.DocDate
FROM OITM T0 INNER JOIN OITB T1
ON T0.ItmsGrpCod = T1.ItmsGrpCod INNER JOIN INV1 T2
ON T0.ItemCode = T2.ItemCode INNER JOIN OINV T3
ON T2.DocEntry = T3.DocEntry
WHERE T3.Docdate >='20100101' AND T3.Docdate <= '20101231'
AND T2.TargetType <> '14' ) source ) VIEW2
LEFT OUTER JOIN
(select ItemCode, SUM(LineTotal) As POSum from POR1
group by ItemCode) POItemSum
ON VIEW2.ItemCode =POItemSum.ItemCode
Group by VIEW2.ItemCode, VIEW2.OnHand,VIEW2.ItemName, VIEW2.ItmsGrpNam,
ISNULL(POItemSum.POSum,0.000000)
Hope this helps
Krishnan
Similar Messages
-
Hello.
I have a query with LEFT OUTER JOIN that I think returns invalid results. Here are the problem details:
CREATE TABLE DOGERR(
IdDog INTEGER,
SfPdg CHAR(1),
IdVpl INTEGER,
SfVpGot INTEGER,
SfZrr CHAR(1)
INSERT INTO DOGERR(IdDog, SfPdg, IdVpl, SfVpGot, SfZrr) VALUES (1, 'S', 1, 1, '7');
INSERT INTO DOGERR(IdDog, SfPdg, IdVpl, SfVpGot, SfZrr) VALUES (2, 'S', 1, 1, '7');
INSERT INTO DOGERR(IdDog, SfPdg, IdVpl, SfVpGot, SfZrr) VALUES (3, '$', 1, 2, 'C');
COMMIT;
CREATE UNIQUE INDEX DOGERR_PK ON DOGERR(IdDog);
And now the query:
SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGotJoin, T.SfZrr AS SfZrrJoin
FROM DOGERR D
LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S' OR SfPdg = 'S') T ON
T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
WHERE
D.IdDog = 3
AND D.SfVpGot = 2
AND D.SfZrr = 'C';
This query should (by my understanding) return only one row in wich the joined subquery columns should be NULL. And indeed query returns only one row on Oracle Database 10g Release 10.2.0.1.0 - Production and on Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production:
IDDOG = 3, SFPDG = "$", IDVPL = 1, SFVPGOT = 2, SFZRR = "C", IDVPLJOIN = NULL, SFVPGOTJOIN = NULL, SFZRRJOIN = NULL
But on Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production it returns TWO rows:
IDDOG = 3, SFPDG = "$", IDVPL = 1, SFVPGOT = 2, SFZRR = "C", IDVPLJOIN = 1, SFVPGOTJOIN = 1, SFZRRJOIN = "7"
IDDOG = 3, SFPDG = "$", IDVPL = 1, SFVPGOT = 2, SFZRR = "C", IDVPLJOIN = 1, SFVPGOTJOIN = 1, SFZRRJOIN = "7"
And now the interesting part: any of the following modified versions of query works even on Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production, although modifications should not modify the result set:
-- Removed unnecessary WHERE conditions
SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGotJoin, T.SfZrr AS SfZrrJoin
FROM DOGERR D
LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S' OR SfPdg = 'S') T ON
T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
WHERE
D.IdDog = 3;
-- Removed unnecessary OR condition in subquery
SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGotJoin, T.SfZrr AS SfZrrJoin
FROM DOGERR D
LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S') T ON
T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
WHERE
D.IdDog = 3
AND D.SfVpGot = 2
AND D.SfZrr = 'C';
-- Removed columns from joined subquery from SELECT part
SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGotJoin
FROM DOGERR D
LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S' OR SfPdg = 'S') T ON
T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
WHERE
D.IdDog = 3
AND D.SfVpGot = 2
AND D.SfZrr = 'C';
NOTE: the query itself is a little stupid but this is just to demonstrate the problem. We have faced this problem at a customer with our real-world query.
So, my question is: why different results ?
Thanks.
Davidhi,
welcome to the forum,
don't have a solution, but I thought I'd let you know that the first SQL statement only returns 1 row on 10gR2
SQL> SELECT D.IdDog, D.SfPdg, D.IdVpl, D.SfVpGot, D.SfZrr, T.IdVpl AS IdVplJoin, T.SfVpGot AS SfVpGo
tJoin, T.SfZrr AS SfZrrJoin
2 FROM DOGERR D
3 LEFT OUTER JOIN (SELECT * FROM DOGERR WHERE SfPdg = 'S' OR SfPdg = 'S') T ON
4 T.IdVpl = D.IdVpl AND T.SfVpGot = D.SfVpGot AND T.SfZrr = D.SfZrr
5 WHERE
6 D.IdDog = 3
7 AND D.SfVpGot = 2
8 AND D.SfZrr = 'C';
IDDOG S IDVPL SFVPGOT S IDVPLJOIN SFVPGOTJOIN S
3 $ 1 2 C
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Solaris: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production -
Is it possible to update a query with another query?
I'm trying to update a query with another query (see attached
code). Here's my setup: I've got a table in an Access database in
which I enter a string into a form and update. This string
corresponds to a single record in another table of the same
datasource. The first table has only one record to provide the
second, which has many and will have more. Basically what I'm
wondering is: Is this a valid thing to do in coldfusion? If not
please help with an alterate method. I'm still a novice at
coldfusion.
The overall effect I'm going for is to display the one record
as a featured truck profile on the web site:
www.truckerstoystore.net.
I currently get an error when I try to display the page with the
current query setup.
Check this page to see the error:
www.truckerstoystore.net/currentTOW2.cfm
Help on this issue is very much appreciated.
------------------------------------------------------------------------------------------ -----------------------------------------------------------------------I think this is what you are after
<!--- this query will get all the records from the DB
--->
<cfquery name="cTOW" datasource="tow">
SELECT *
FROM currentTOW
<!--- Do you need to find a particular record in the
database --->
<!--- If so, then you need a 'where' clause in here
--->
</cfquery>
<!-- Loop the cTOW query for each record returned -->
<cfloop query="cTOW">
<!--- For the record returned from the cTOW query you now
need to update the table --->
<!-- Update the table -->
<cfquery name="currentTOW" datasource="tow">
UPDATE Your tblName
SET
Dataname = cTOW.DataValue
</cfquery>
</cfloop>
thats it
PS: I think your original query needs modifying. To return
the exact records that you want to update from the original table.
ie: Primary and foreign key relationship -
Outer join on query with OR clause
hi all, i am having problem outerjoining a query with or clause
here is my data
WITH table1 AS
SELECT 'test' txt1, 'pak' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL
SELECT null txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL
SELECT null txt1, NULL txt2, 'ced3' txt3, 'su3' txt4 FROM dual UNION ALL
SELECT null txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
SELECT 'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
SELECT null txt1, NULL txt2, null txt3, null txt4 FROM dual
,table2 AS
SELECT 111 pid, 'test' txt1, 'pak4' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL
SELECT 222 pid, 'test1' txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL
SELECT 333 pid, 'test2' txt1, 'pak3' txt2, 'ced3' txt3, 'su4' txt4 FROM dual UNION ALL
SELECT 444 pid, 'test2' txt1, 'pak3' txt2, 'ced4' txt3, 'su3' txt4 FROM dual
SELECT b.pid, a.*
from table1 a, table2 b
WHERE (a.txt1 = b.txt1 OR
a.txt1 IS NULL AND a.txt2=b.txt2 OR
Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 = b.txt3 OR
Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 IS NULL AND a.txt4 = b.txt4
) as you can see i am joining table1 and table 2. i am joining with txt1, if txt1 is null then join by txt2, if null then join by txt3 and so on.
the code above product this output
PID TXT1 TXT2 TXT3 TXT4
=== ==== === ==== ====
111 test pak ced su
222 pak ced2 su2
333 ced3 su3
444 su3this output is partially correct. only 4 rows were display and two was left out
SELECT 'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
SELECT null txt1, NULL txt2, null txt3, null txt4 FROM dual i tried using outer join but oracle complain that i cannot use outerjoin with OR clause.
can someone help modify my query to display the output below ?
PID TXT1 TXT2 TXT3 TXT4
=== ==== === ==== ====
111 test pak ced su
222 pak ced2 su2
333 ced3 su3
444 su3
NULL NULL NULL NULL NULL
test5Not sure you can do it with the Oracle style outer joins, but wioth ANSI style joins it is simple, actually exactly as you had it.
SQL> set null null;
SQL> WITH table1 AS (
2 SELECT 'test' txt1, 'pak' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL
3 SELECT null txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL
4 SELECT null txt1, NULL txt2, 'ced3' txt3, 'su3' txt4 FROM dual UNION ALL
5 SELECT null txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
6 SELECT 'text5' txt1, NULL txt2, null txt3, 'su3' txt4 FROM dual UNION ALL
7 SELECT null txt1, NULL txt2, null txt3, null txt4 FROM dual),
8 table2 AS (
9 SELECT 111 pid, 'test' txt1, 'pak4' txt2, 'ced' txt3, 'su' txt4 FROM dual UNION ALL
10 SELECT 222 pid, 'test1' txt1, 'pak' txt2, 'ced2' txt3, 'su2' txt4 FROM dual UNION ALL
11 SELECT 333 pid, 'test2' txt1, 'pak3' txt2, 'ced3' txt3, 'su4' txt4 FROM dual UNION ALL
12 SELECT 444 pid, 'test2' txt1, 'pak3' txt2, 'ced4' txt3, 'su3' txt4 FROM dual)
13 SELECT b.pid, a.*
14 from table1 a
15 LEFT JOIN table2 b
16 ON (a.txt1 = b.txt1 OR
17 a.txt1 IS NULL AND a.txt2=b.txt2 OR
18 Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 = b.txt3 OR
19 Nvl(a.txt2, a.txt1) IS NULL AND a.txt3 IS NULL AND a.txt4 = b.txt4);
PID TXT1 TXT2 TXT3 TXT4
111 test pak ced su
222 null pak ced2 su2
333 null null ced3 su3
444 null null null su3
null text5 null null su3
null null null null nullJohn -
Update query with CL_SQL_STATEMENT class
Hi all,
I'm trying to execute an update query with ADBC classes in order to modify two parameters (n_doc and processed) from a row with the following instructions:
l_con_ref = cl_sql_connection=>get_connection( 'DB_7879' ).
l_stmt_ref = l_con_ref->create_statement( ).
CONCATENATE 'update' gv_table ' set n_doc= ? processed = ''X'' where id_ordn = ? ' INTO l_stmt SEPARATED BY space.
GET REFERENCE OF materialdocument INTO l_dref.
l_stmt_ref->set_param( l_dref ).
GET REFERENCE OF ps_zmm_mov-id_ordn INTO l_dref.
l_stmt_ref->set_param( l_dref ).
l_stmt_ref->execute_update( l_stmt ).
However, I got the error ORA-0933: SQL command not properly ended. I guess this error occurs because I am trying to update two parameters with a single query since using the following CONCATENATE instruction
CONCATENATE 'update' gv_table ' set n_doc= ? where id_ordn = ? ' INTO l_stmt SEPARATED BY space.
results ok.
Does anybody know if it is possible to modify two parameters with only one update query with ADBC classes?
Thank you in advance!Hi Suhas,
Based on Oracle, I see it conforms almost completely ISO/IEC 9075 ([Oracle and Standard SQL|http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/ap_standard_sql.htm#10293])
UPDATE seems to conform completely [UPDATE SET clause|http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_108a.htm#2087215]
So using a comma to separate columns is true for every SQL language that conforms ISO/IEC 9075
Sandra
PS: of course SAP's "Open SQL" language does not conform at all -
Cfldap modify query to add members to group
Hi,
I am trying to add new members to the group using cfldap modify query.
i am able replace with one member with the other but the requirement is like that we supposed to add new member with the existing one.
query that i have used is
<cfldap
ACTION="modify"
Modifytype="REPLACE"
DN="#groupdn#"
ATTRIBUTES="MEMBER=#existingmembers#, cn=XXX, ou=xxx,o=xxxx"
separator="|"
secure="#secure#"
server="#ldapServer#"
username="#ldapuser#"
password="#ldapPassword#"
port="#ldapPort#"
>
It is giving syntax violation error.
please help me get it resolved.
Thanks in advance.Just to add to the query above, if you want to see request group along with request_group_id you do join as follows
SELECT frv.responsibility_name
,frg.request_group_name
FROM fnd_request_groups frg,
fnd_request_group_units frgu,
fnd_responsibility_vl frv
WHERE 1 = 1
AND frgu.request_group_id = frg.request_group_id
AND frv.request_group_id = frg.request_group_id
ORDER BY responsibility_name
Thanks
Shailendra -
Crash - CR 2008 crashes constantly when trying to modify query parameters
Hello,
When i create a query with 2 parameters of type Date or Date/Time.
If I try to modify the query sometime after, Crystal Report crashes all the time.
If i create only 1 parameter of type Date or Date Time, I can modify the query without any problems.
Any idea why?
Is there a workaround?
ThanksInstall SP2 and test again. If it's still an issue re-post your question.
-
Is it possible to join the table PCH1 directly to POR1?
Or have I to use PDN1 in between?
What is then the correct query?
Thanks in advance,
FritsYou are right. I placed PDN1 in between and it seems now ok. The idea was to create a query with less tables and the same result. Thanks for checking.
SELECT "PCH1"."ItemCode", "PCH1"."Quantity", "PCH1"."Price", "OPOR"."DocNum", "OPCH"."DocNum", "POR1"."Dscription"
FROM ((("Veenstra_Template"."dbo"."PDN1" "PDN1" INNER JOIN "Veenstra_Template"."dbo"."PCH1" "PCH1" ON ("PDN1"."DocEntry"="PCH1"."BaseEntry") AND ("PDN1"."LineNum"="PCH1"."BaseLine")) INNER JOIN "Veenstra_Template"."dbo"."POR1" "POR1" ON ("PDN1"."BaseEntry"="POR1"."DocEntry") AND ("PDN1"."BaseLine"="POR1"."LineNum")) INNER JOIN "Veenstra_Template"."dbo"."OPOR" "OPOR" ON "POR1"."DocEntry"="OPOR"."DocEntry") INNER JOIN "Veenstra_Template"."dbo"."OPCH" "OPCH" ON "PCH1"."DocEntry"="OPCH"."DocEntry"
ORDER BY "OPCH"."DocNum"
Best regards,
Frits -
Ora-03114 running a query with group by
Hi, I've a query with a group by on a sub-query, something like
SELECT <40+ fields>
FROM (SELECT <40+ fields>
FROM table
GROUP BY <40+ fields> I don't have any problem running this query directly via toad. This query is a cursor in a procedure in a package and, if I invoke it on the same data, the session crash "with ora-03114 not connected to oracle". If I modify the query selecting less fields, 22, I don't have any problem while with 23 the crash appears.
Furthermore, I don't have any problem in other databases with similar data.
The db version is 9.2.0.6.0 - 64bit
Any idea/advice?
Edited by: 912104 on 3-feb-2012 2.02
Edited by: 912104 on 3-feb-2012 2.03
Edited by: 912104 on 3-feb-2012 2.03912104 wrote:
I have difficult to have more information, I can only add:
select * from v$version
BANNER
Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
PL/SQL Release 9.2.0.6.0 - Production
CORE 9.2.0.6.0 ; Production
TNS for IBM/AIX RISC System/6000: Version 9.2.0.6.0 - Production
NLSRTL Version 9.2.0.6.0 - Production Can I ask what do you think about the different behavior via toad and via package? I mean, it's possible that is a server bug?
Edited by: 912104 on 3-feb-2012 4.02Are you retrieving the entire result set via toad? or just the first few records?
Are there any TOAD non-fetched column values in your result set, i.e. CLOBS, XMLTypes, nested types?
What does your code do with the cursor? Presumably you don't loop through it and do nothing. Are you sure it's the select that's causing the error, or something you are doing with the data in the procedure?
Can you not adding some instrumentation to your code so that you know exactly what line/data values are processed at the time of the crash? Does it always crash on the same values/line or does it vary?
"Furthermore, I don't have any problem in other databases with similar data." ... what do you mean by "similar data". You only need one odd value in one column to cause you a 3114 in the right circumstances. It seems like you are long way off establishing what exactly the problem is. It's always useful not to close doors to lines of thought. You need to systematically track down the root cause of the issue by exclusion and assumptions are the enemy of that process. -
Repeated rows resulting from executeWithParams on query with bind variable
hi
Please consider this example application created using JDeveloper 11.1.1.3.0
at http://www.consideringred.com/files/oracle/2010/RepeatedRowsIssueApp-v0.01.zip
It has a View Object "EmployeesVO" based on a SQL query with a bind variable "EmailBVar".
The page "findEmployees.jspx" has executeWithParams dropped as an "ADF Parameter Form..." and the "EmployeesVOVI" collection as a table.
On "EmployeesVOVIIterator" the RangeSize has been modified from the default 25 to 10.
So, all straightforward stuff.
A scenario (sc1), running the page "findEmployees.jspx", specifying a value and clicking the "ExecuteWithParams" button results in repeated rows shown in the table, that is the first row (and subsequent rows) are repeated at row 11 (and subsequent rows),
as can be seen in the screencast at http://screencast.com/t/bn9QvV0qt
question:
- (q1) How can the repeated rows in scenario (sc1) be explained/avoided?
many thanks
Jan VerveckenThanks for your reply Nick Haralabidis.
it can be avoided by setting the EmployeesVO Access Mode to Range Paging and setting the Range Size to 10. Indeed, that does seem to avoid the repeating rows.
Now why you get this behavior when you don't specify Range Paging on the VO I don't know. It could be because: 1) it is a bug - the obvious answer ;) , 2) because setting the RangeSize on the EmployeesVOVIIterator without setting the Access Mode on the EmployeesVO to Range Paging is conflicting - but then again there is no warning or error produced by JDeveloper, 3) ...It does look like unintended behaviour, for a "default approach" like this.
In documentation section "39.1.5 Efficiently Scrolling Through Large Result Sets Using Range Paging " ...
at http://download.oracle.com/docs/cd/E14571_01/web.1111/b31974/bcadvvo.htm#ADFFD1179
... this Range Paging for a View Object seems to be described as an optimization, not as a requirement for functionally correct behaviour.
- about (q1)
Another approach that seems to avoid the repeated rows in scenario (sc1) is removing the value for the RangeSize attribute on the iterator, so the RangeSize is not specified.
Using the modified example application
at http://www.consideringred.com/files/oracle/2010/RepeatedRowsIssueApp-v0.02.zip
... this can be seen in scenario (sc2) in the screencast at http://screencast.com/t/0bpCo33i8J
Although, the documentation in section "22.4.2.2 Iterator RangeSize Attribute " ...
at http://download.oracle.com/docs/cd/E14571_01/web.1111/b31974/web_form.htm#ADFFD706
... does not seem to mention anything about not specifying the RangeSize attribute, it does say "... You can set it to -1 to have the full record set returned. ...".
As can be seen in scenario (sc2) the EL expression #{bindings.EmployeesVOVIIterator.rangeSize} resolves to -1 which suggests that not specifying the RangeSize attribute is the same as configuring the RangeSize attribute to -1.
questions:
- (q2) What is the preferred way to avoid having "the full record set returned", without having repeated rows as in scenario (sc1)?
- (q3) Is the default configuration of RangeSize="25" on the iterator intended behaviour (for an interator supporting an executeWithParams action)?
regards
Jan -
CMC: user must update save but not modify report with webi
Hi experts,
I'm on BO platform 4.0SP2 fp10.
I would like to know if it is possible to enable a user a user to update data in a report, save report but disable it to modify report structure and query.
In a folder the user must be able to update the report and prompt, then he must save it, but I don't want him to modify report with webi.
Thanks
CamilloHi Frederique,
By not modifying the report with WebI, do you mean that the user shouldn't have access to WebI Rich Client?
What kind of update would the user have to do on a report once the report is available in a folder?
Yes I mean user shouldn't ha access to webi rich client. He should just view update rint and updated report.
Regards
Camillo -
How to create an ABAP Query with OR logical expression in the select-where
Hi,
In trying to create an ABAP query with parameters. So it will select data where fields are equal to the parameters entered. The default logical expression is SELECT.. WHERE... AND.. However I want to have an OR logical expression instead of AND.. how can I attain this??
Please help me on this.. Points will be rewarded.
Thanks a lot.
Regards,
Question ManHi Bhupal, Shanthi, and Saipriya,
Thanks for your replies. But that didn't answer my question.
Bhupal,
You cannot just replace AND with OR in an ABAP QUERY. ABAP QUERY is a self generated SAP code. You'll just declare the tables, input parameters and output fields to be displayed and it will create a SAP standard code. If you'll try to change the code and replace the AND with OR in the SAP standard code, the system will require you to enter access key/object key for that particular query.
Shanthi,
Yes, that is exactly what need to have. I need to retireve DATA whenever one of the conditions was satisfied.
Saipriya,
Like what I have said, this is a standard SAP code so we can't do your suggestion.
I have already tried to insert a code in the ABAP query (there's a part there wherein you can have extra code) but that didn't work. Can anybody help me on this.
Thanks a lot.
Points will be rewarded.
Regards,
Question Man -
Error while trying to Execute the Query with Customer Exit
Hi Experts,
I am having a Query with Customer Exit, it is working fine for all the Employess, except for one. When i try to remove the Customer Exit it is working for her too. Below is the error i am getting.
system error in program SAPLLRK0 and form RSRDR; CHECK_NAV_INIT_BACK
Thanks,
Kris.Hello Kris,
Are you working with multiprovider? Please check if OSS notes 813454,840080 or 578948 are applicable in your case.
Regards,
Praveen -
Report on BEx query with 2 structures (one in rows and one in columns)
Hi, experts! I have to make Crystall report on BEx query with 2 structures, one in columns (with KF's), and one in rows. Is it possible to create such report? Because when I create such report, I cant see fields in structures, only characteristics fields.
Ok, I found samr problem in another thread. Sorry.
Edited by: Mikhail Sychev on Dec 5, 2009 9:53 PMHey Flora,
Happy to hear that its working now.
Answering your question, again its upto the connection and report format you are using. Based on your question i hope you your report output should be like this.
You cannot map to two labels for the series, again this report format is possible only in cross tab through Webi. I would suggest you to concatenate the material and month in a dimension in webi like below.
I have done the concatenation in excel level, i would suggest you to do that in webi. Try to reduce the formula as much in excel.
or
If you are using Query browser connection, then i would suggest you to create a separate report which will display the actual vs plan material wise, here you need to pass the material as a prompt.
Hope this helps in clear, please revert me for any clarification. -
Query with bind variable, how can use it in managed bean ?
Hi
I create query with bind variable (BindControlTextValue), this query return description of value that i set in BindControlTextValue variable, how can i use this query in managed bean? I need to set this value in String parameter in managed bean.
ThanksPut the query in a VO and execute it the usual way.
If you need to, you can write a parameterized method in VOImpl that executes the VO query with the parameter and then call that method from the UI (as a methodAction binding) either through the managed bean or via a direct button click on the page.
Maybe you are looking for
-
Acrobat Reader don't allow this file type to be opened! (Excel)
I have several PDF files that were generated in a previous version of Adobe Acrobat. They are converted folders from outlook into PDF. These PDF's contain email communication about a certain topic. Some of the emails contain attachments, like excel w
-
I hope u can help me. I'm trying to capture reports of .rdf type. Although it is captured succesfully into the repository, i get this warning: CGEN-03362: Module: no repository elements found to map application logic on: '%' (Modular, Format trigger,
-
Illustrator CS6 Stability Issues- crashing every 5 minutes
Hi All, I've been having serious stability issues with Illustrator ever since I upgraded from CS5.5 to CS6. It crashes like every 5 minutes, mostly when I use the "nevigator" tool to pan to another area of the artboard. The windows messsage was somet
-
I am pleased to announce that a prototype version is available for Win32 and Linux32. We are willing to gather feedback from experts in the field of AOP, bytecode instrumentation, APM and similar techniques. If you are willing to evaluate this techno
-
Unable to open downloaded game. Says need to be administrator/I am. Repair disk permissions w/disk utility no help...what do I do?