Query help op duplicate lines
Hi Experts,
I have a client who needs a Report that show the Item availability and what Sales Order makes up the 'Committed Stock' and what Purchase Orders make up the 'Ordered Stock' quantity in the Item Master Inventory tab.
Here is what I did so far:
SELECT T0.[ItemCode], T0.[ItemName], T0.[OnHand], T0.[IsCommited], T0.[OnOrder], T0.[OnHand] - T0.[IsCommited] + T0.[OnOrder] AS 'Available', T1.[DocEntry] AS 'SALES ORDER', T2.[CardCode] AS 'Customer Code', T2.[CardName] AS 'Customer Name', T1.[Quantity]AS 'SO Qty',T4.[DocNum] AS 'PURCHASE ORDER', T4.[CardCode] AS 'Vendor Code', T4.[CardName] AS 'Vendor Name',T3.[Quantity] AS 'PO Qty' FROM [dbo].[OITM] T0 INNER JOIN [dbo].[RDR1] T1 ON T0.ItemCode = T1.ItemCode INNER JOIN [dbo].[ORDR] T2 ON T1.DocEntry = T2.DocEntry INNER JOIN [dbo].[POR1] T3 ON T0.ItemCode = T3.ItemCode INNER JOIN [dbo].[OPOR] T4 ON T3.DocEntry = T4.DocEntry WHERE T0.[ItemCode] = 'A00008'
The issue here is that when I have more Sales Orders than Purchase Orders it just fills in the lines with duplicate Purchase Orders.
Any help would be appreciated.
Thanks,
Marli
Hi Marli,
If you need detail break down, you have to separate the results to two queries. There are no relations between those SO and PO. You could not get them in one report without issue.
Thanks,
Gordon
Similar Messages
-
Activate function "Duplicate Line" in a UDO - SAP 8.8
He everybody,
I've created a basic UDO in SAP 8.8... How can I activate "Duplicate Line" function in this UDO, like exist in SAP B1 default forms??
It is possible??
Rgrds,
WagnerHi Wagner,
you have to develop this function on your own. You can use the generalservices for accessing udo data. see the sdk help center for more information.
greetings
matthias -
Query to conbine 2 lines from table
Hi all
I have a problem in constructing sql query to combine 2 lines from table in Oracle 11g database.
I will explain, i have one table containing call transactions loaded in one table from 2 different sources, one is from IN which is tagged IN and the other from MSC which is tagged MSC. One subscriber call is registered in IN and MSC and loaded in the table. The problem is the data from IN contains the call duration but not contains Cell information. I'm creating datamart to combine the two lines in one lines but i don't know how to do from query.
Here is an overview if my data:
Source Orig Dest startdate cellid duration
MSC 550000 220000 15/05/2012 02:03:29 235e
IN 550000 220000 15/05/2012 02:03:30 10
MSC 550000 220000 15/05/2012 02:04:00 235e
IN 550000 220000 15/05/2012 02:03:59 15
MSC 550000 220001 15/05/2012 02:06:18 235f
IN 550000 220001 15/05/2012 02:06:18 60
The line i want to have is for each line of IN source i sjhould have the cellid like below:
IN 550000 220000 15/05/2012 02:03:30 235e 10
IN 550000 220000 15/05/2012 02:03:59 235e 15
IN 550000 220001 15/05/2012 02:06:18 235f 60
The query should linked by Orig, Dest and date but for some rows there are difference in seconds.
Please help.
Lucienot.user13513449 wrote:
Hi
Thanks for the reply, here below the create table script and some insert data example:
CREATE TABLE TRANS
CALLTRANSTYPE NVARCHAR2(6),
ORIGANI NVARCHAR2(40),
TERMANI NVARCHAR2(40),
STARTTIME DATE,
STOPTIME DATE,
CELLID NVARCHAR2(10),
CONNECTSECONDS NUMBER,
SWITCHCALLCHARGE NUMBER
0 555283806 222591626 05/15/2012 00:10:04 05/15/2012 00:13:31 03e9:7565 O 207.00
Insert into trans values('MSG','555283806','222591626',to_date('05/15/2012 00:10:04','mm/dd/yyyy hh24:mi:ss'),to_date('05/15/2012 00:13:31','mm/dd/yyyy hh24:mi:ss'),'03e9:7565',10,null); ...It looks like there's some mistake at the end of the CREATE TABLE statement and before the first INSERT statement. Is that supposed to be another INSERT statement?
Test your code and, if necessary, correct it before you post it.
Is that sample data supposed to produce the results you posted originally?
If so, explain, step by step, ho9w you get them.
If not, post the results you want from that smaple data, formatted, between \ tags, as explained in the forum FAQ {message:id=9360002}
In my orioginal message, I said "ORDER BY" where I meant "GROUP BY". If you change that, and use your new table and column names, does the query I posted earlier do what you want? If not, point out where it is wrong, and show how you might get the right results in those places. -
I have a table that lists some data. Every day should have one and only one record per organization. I am trying to weed out the duplicates in one query. It doesn't matter which of the duplicates gets deleted, so I could use a (where rownum = 2) clause, but I'm not sure how to get there.
This query exposes the duplicates:
select DATE_INDEX, ORG_ID
from STAFFING_TURNOVER
group by DATE_INDEX, ORG_ID
having COUNT(ID) > 1
order by DATE_INDEX, ORG_IDCan someone help me turn this into a delete query that deletes the second record? Because it is based on a combination of date + organization, the syntax for a subquery-based delete is escaping me.Delete from STAFFING_TURNOVER Where RowID in
(Select Min(RowID) From STAFFING_TURNOVER Group by DATE_INDEX, ORG_ID Having Count(1) > 1)
Oops, someone posted the same thing.
If you need to you can execute it more than once if you have more than one. You can also perform an elegant minus query or use a Sub-query to ID the dups. The problem will be performance and depend on how much data you have.
Edited by: Dev on Dec 1, 2010 3:25 PM -
Dear all,
i have a table
create table attendance(dept_id number,att_date date,att_kind);
all the three columns i want to put as a primary key,
there is a data in the table.
how would i check through a query that the table has duplicate values or not?
in other words , i want to query just the duplicate records so i delete them manually.
thanks & RegardsYou do it like this.
SQL> select * from attendance;
DEPT_ID ATT_DATE ATT_KIND
100 20-FEB-10 1
100 20-FEB-10 1
200 20-FEB-10 1
200 20-FEB-10 2
SQL> create table exceptions(row_id rowid,
2 owner varchar2(30),
3 table_name varchar2(30),
4 constraint varchar2(30));
Table created.
SQL> alter table attendance add constraint att_pk primary key (dept_id, att_date, att_kind) exceptions into exceptions;
alter table attendance add constraint att_pk primary key (dept_id, att_date, att_kind) exceptions into exceptions
ERROR at line 1:
ORA-02437: cannot validate (TEST.ATT_PK) - primary key violated
SQL> select * from exceptions;
ROW_ID OWNER TABLE_NAME CONSTRAINT
AAAC/yAAGAAAAAOAAB TEST ATTENDANCE ATT_PK
AAAC/yAAGAAAAAOAAA TEST ATTENDANCE ATT_PK
SQL> select * from attendance where rowid in (select row_id from exceptions);
DEPT_ID ATT_DATE ATT_KIND
100 20-FEB-10 1
100 20-FEB-10 1
SQL>Asif Momen
http://momendba.blogspot.com -
Query Help:
http://forum.java.sun.com/thread.jsp?forum=45&thread=471180&tstart=15&trange=15
It seems I have confused enough people with my improper presentation of query. Sorry guys. I will restate my question with different table names.
The above was my previous posting, which was not clear..so Iam restating my problem as follows....
I have the following tables
Customer(custID, Name, Address)
Order(custID, OrderID, orderDate)
CreditCard(custID, creditCard#, creditCardType)
Now if I have 3 records in Order with custID 100 and 2 records in CreditCard as
Order:
100,A001,11/22/03
100,A002,11/24/03
100,A003,12/02/03
CreditCard:
100,42323232..., VISA
100,5234234...., MASTER
Now how can I get
custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
data in minimum no. of records....
I think I have made my query clear..
now please help me guys...
thanks so much for your help.You are right.
But frankly the actual tables on my database are not customer,orders and creditcards..but I just tried to reproduce the problem with these tables, please ignore that user needs a refund etc situtaion. If the tables were actually order,creditcards etc..it would have been a problem to be considered.
Can you please help me with the query
if I have m rows in Order and n rows in CreditCard. I will get m*n records, I looking for max(m,n).
With the following fields in my query result,
custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
from Customer, Order, CreditCard tables
Thanks so much for your htlp -
SAP QUERY report for vendor line items
Hi
I have created a SAP QUERY report for vendor line items with fields vendor no.,vendor name,amount,company code and period.But there is one line item i donot know from wher system is getting it picked with is not in that vedor account,when i compare with fbl1n.I checked the document number too...the same doc number is twice in my query report.One with correct amount and another with wrong one.How do i chk.Where did i go wrong in creating query.I used logical database KDF.
Please advise.i chked...how do we get the amount displayed in query...it just displays amount no debit credit symbol... i have selected BSEG-DMBTR field but no -/+ sign,how is it done in query,please suggest.
-
SQL Query Help - Is this possible or impossible????
Hi guys,
I need help with an SQL query that I'm trying to develop. It's very easy to explain but when trying to implement it, I'm struggling to achieve the results that I want.....
For example,
I have 2 tables
The first table is:
1) COMPANY create table company (manufacturer varchar2(25),
date_established date,
location varchar2(25) );My sample test date is:
insert into company values ('Ford', 1902, 'USA');
insert into company values ('BMW', 1910, 'Germany');
insert into company values ('Tata', 1922, 'India');The second table is:
2) MODELS create table models (manufacturer varchar(25),
model varchar2(25),
price number(10),
year date,
current_production_status varchar2(1) ) ;My sample test data is:
insert into models values ('Ford', 'Mondeo', 10000, 2010, 0);
insert into models values ('Ford', 'Galaxy', 12000, 2008, 0);
insert into models values ('Ford', 'Escort', 10000, 1992, 1);
insert into models values ('BMW', '318', 17500, 2010, 0);
insert into models values ('BMW', '535d', 32000, 2006, 0);
insert into models values ('BMW', 'Z4', 10000, 1992, 0);
insert into models values ('Tata', 'Safari', 4000, 1999, 0);
insert into models values ('Tata', 'Sumo', 5500, 1996, 1);
insert into models values ('Tata', 'Maruti', 3500, 1998, 0);And this is my query:
SELECT
com.manufacturer,
com.date_established,
com.location,
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
mod.current_production_status
FROM
company com,
models mod
WHERE
mod.manufacturer = com.manufacturer
and com.manufacturer IN ('Ford', 'BMW', 'Tata')
and mod.current_production_status IN (1,0)
ORDER BY
mod.current_production_status DESCWhat I want the query to output is this:
com.manufacturer com.date_established com.location mod.model mod.price mod.year mod.current_production_status
Ford 1902 USA Escort 10000 1992 1
BMW 1910 Germany - - - 0
Tata 1922 India Sumo 5500 1998 1If current_production_status is 1 it means this particular model has been discontinued
If current_production_status is 0 it means the manufacturer does not have any discontinued models and all are in procuction.
The rule is only one record per manufacturer is allowed to have a current_production_status of 1 (so only one model from the selection the manufactuer offers is allowed to be discontinued).
So the query should output the one row where current_production_status is 1 for each manufacturer.
If for a given manufacturer there are no discontinued models and all have a current_production_status of 0 then ouput a SINGLE row that only includes the data from the COMPANY table (as above). The rest of the columns from the MODELS table should be populated with a '-' (hyphen).
My query as it is above will output all the records where current status is 1 or 0 like this
com.manufacturer com.date_established com.location mod.model mod.price mod.year mod.current_production_status
Ford 1902 USA Escort 10000 1992 1
Tata 1922 India Sumo 5500 1998 1
Ford 1902 USA - - - 0
Ford 1902 USA - - - 0
BMW 1910 Germany - - - 0
BMW 1910 Germany - - - 0
BMW 1910 Germany - - - 0
Tata 1922 India - - - 0
Tata 1922 India - - - 0However this is not what I want.
Any ideas how I can achieve the result I need?
Thanks!
P.S. Database version is '10.2.0.1.0'Hi Vishnu,
Karthiks query helped...
But this is the problem I am facing...
SELECT
com.manufacturer,
com.date_established,
com.location,
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
mod.current_production_status
FROM
company com,
models mod
WHERE
mod.manufacturer = com.manufacturer
and com.manufacturer = 'Ford'
and mod.current_production_status IN (1,0)
ORDER BY
mod.current_production_status DESCThe value of:
and com.manufacturer = 'Ford'will be dependent on front end user input....
When I run the query above I get all the rows where current_production_status is either 1 or 0.
I only require the rows where current_production_status is 1.
So if I amend it to look like this:
and mod.current_production_status = 1This works....
BUT if a user now passes in more than one manufacturer EG:
and com.manufacturer IN ('Ford', 'BMW')The query will only return the one row for Ford where current_production_status is 1. However because BMW has no models where current_production_status is 1 (all 3 are 0), I still want this to be output - as one row....
So like this:
com.manufacturer com.date_established com.location mod.model mod.price mod.year mod.current_production_status
Ford 1902 USA Escort 10000 1992 1
BMW 1910 Germany - - - 0So (hopefully you understand), I want both cases to be catered for.....whether a user enters one manufacturer or more than one...
Thanks you so much!
This is really driving me insane :-( -
New error message :duplicate line item
Hi,
We have to add a new error message so that when we try to add a duplicate line item in our qty contract
1. we should not be allowed
2. we should get a error message u201Cduplicate line item not allowedu2019
How to achieve this
Thanks
ArunSearch this forum for "USEREXIT_SAVE_DOCUMENT" and "USEREXIT_SAVE_PREPARE".
-
Duplicate line item in Statement of account
Dear All,
Why there is duplicate line item in Statement of account?Hi Ajit,
In your ECC system follow below path and set Availability check rule to "B" (full delivery).
SPRO --> SD --> Basic Functions --> Availability Check and TOR --> Availability Check --> Availability Check with ATP Logic or Against Planning --> Define Default Settings
Select your sales area and set Availability check rule to "B" (full delivery).
This should fulfill your requirement.
Rgds
Sourabh -
Query on FI AP:Line item Cube
Hi bw guys i have one query on FI AP:Line item cube(ZFIAP_C03).The cube is customised and it resembles the business content cube 0FIAP_C03.I would like to know that what is the use of the customised cube (ZFIAP_C03).What does the cube analyse and what are the fields that are based on the factor that the cube analyses.
for example the cube 0SD_C03 is a sales overview cube and it is used to analyse actual sales at the following levels
company code
sales org
sales district
region
sales office
sales employee.
i would like to know that what does a FI AP:Line item cube(ZFIAP_C03) analyses and what are the levels that the cube analyses
the characteristics in the cube ZFIAP_C03 are
Company code
Branch
Dunning area
Dunning level
Last dunned
Clearing
Payment method
Reason code
Terms of Payment
Cash discount 1
Cash discount 2
Net due date
Net due date
Chart of accounts
G/L Account
Document Date
Document no.
Document type
Item
Item Status
Posting date
Posting key
The keyfigures are
Amount
Cash discount amount
Credit amt in FC
Credit amt in LC
Debit amt in FC
Debit amt in LC
Debit/Credit Amount
Discount amt
Discount base
Thank You.It looks almost identical to the std content AP cibe and s used to analyse vendor payables
Ie creditors balances and the ageing of them and the dat aoriginates from BSIK and BSAK inside R3 -
Numbering query results with a line number in SQL*Plus
Doesn't it stand to reason that in SQL*Plus there would be a way to number each query results sequentially with line numbers starting at 1 to n -- something option like from a SET command? I'm not talking about linesize.
There's a column rownum the engine adds into the result sets, just add it to the select list. Can use it to limit the result set (with some limitations) i.e.:
select rownum, ... from ... where rownum <= 100
Can't use ">=", that condition will never be met but a subset could be used:
select * from ( select rownum as linenr, tab1.* from ... ) where linenr between 10 and 20 -
Activate funcions "Duplicate Line" in UDO-Table
He everybody,
I've created a basic UDO... How can I activate "Duplicate Line" function in this UDO, like exist in SAP B1 default forms??
It is possible??
Rgrds,
WagnerHi Wagner,
Your question belongs to SDK forum. Post it there.
Thanks,
Gordon -
Problem of running the jump query from the result line
Dear expert,
I have a problem when running a jump query from the result line. Apparently, the values of the caracteristics haven't been sent to the jump target. However, the configuration in RSBBS seems to be good as the jump works well from the other lines.
Does anyone have some ideas on that?
Thanks in advance!Hi,
If you are supposed to bring across characteristic values to your target, then you will not be able to jump from the result line. The configuration expects that the values of the characteristic marked as being used in the jump are filled with unique values. When you use the result line as a source for your jump, the values in the result line will most likely be based on the sum of multiple characteristic values.
Hth,
-Jacob -
hi, i have duplicate lines, how to keep one line and delete other line, please see the data.
GEOMETRY(SDO_GTYPE, SDO_SRID, SDO_POINT(X, Y, Z), SDO_ELEM_INFO, SDO_ORDINATES)
SDO_GEOMETRY(2002, 8307, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), SDO_ORDINATE_ARRAY(
-87.913022, 41.977339, -87.912718, 41.977415))
SDO_GEOMETRY(2002, 8307, NULL, SDO_ELEM_INFO_ARRAY(1, 2, 1), SDO_ORDINATE_ARRAY(
-87.913022, 41.977339, -87.912718, 41.977415))
many thanksHi 908275,
Here's a quick demo:jot_test@11gR2> create table duplicate_demo (
2 id number primary key,
3 geometry sdo_geometry);
Table created.
jot_test@11gR2>
jot_test@11gR2> delete from user_sdo_geom_metadata where table_name = 'DUPLICATE_DEMO';
1 row deleted.
jot_test@11gR2> insert into user_sdo_geom_metadata (table_name, column_name, diminfo, srid) values
2 ('DUPLICATE_DEMO','GEOMETRY',sdo_dim_array(sdo_dim_element('x', 600000, 650000, .01), sdo_dim_element('y', 300000, 350000, .01)), 81989);
1 row created.
jot_test@11gR2>
jot_test@11gR2> create index duplicate_demo_spind on duplicate_demo(geometry) indextype is mdsys.spatial_index;
Index created.
jot_test@11gR2>
jot_test@11gR2> insert into duplicate_demo (id, geometry) values (1,
2 sdo_geometry(2003, 81989, null, sdo_elem_info_array(1,1003,1),
3 sdo_ordinate_array(600000, 300000, 601000, 300000, 601000, 301000, 600000, 301000,600000, 300000)));
1 row created.
jot_test@11gR2>
jot_test@11gR2> insert into duplicate_demo (id, geometry) values (2,
2 sdo_geometry(2003, 81989, null, sdo_elem_info_array(1,1003,1),
3 sdo_ordinate_array(600000, 300000, 601000, 300000, 601000, 301000, 600000, 301000,600000, 300000)));
1 row created.
jot_test@11gR2>
jot_test@11gR2> insert into duplicate_demo (id, geometry) values (3,
2 sdo_geometry(2003, 81989, null, sdo_elem_info_array(1,1003,1),
3 sdo_ordinate_array(600000, 300000, 601000, 300000, 601000, 301000, 600000, 301000,600000, 300000)));
1 row created.
jot_test@11gR2>
jot_test@11gR2> insert into duplicate_demo (id, geometry) values (4,
2 sdo_geometry(2003, 81989, null,sdo_elem_info_array(1,1003,1),
3 sdo_ordinate_array(600200, 300200, 601500, 300200, 601500, 303000, 600200, 303000,600200, 300200)));
1 row created.
jot_test@11gR2>
jot_test@11gR2> insert into duplicate_demo (id, geometry) values (5,
2 sdo_geometry(2003, 81989, null,sdo_elem_info_array(1,1003,1),
3 sdo_ordinate_array(600200, 300200, 601500, 300200, 601500, 303000, 600200, 303000,600200, 300200)));
1 row created.
jot_test@11gR2>
jot_test@11gR2> insert into duplicate_demo (id, geometry) values (6,
2 sdo_geometry(2003, 81989, null,sdo_elem_info_array(1,1003,1),
3 sdo_ordinate_array(600200, 300200, 601500, 300200, 601500, 303000, 600200, 303000,600200, 300200)));
1 row created.
jot_test@11gR2>
jot_test@11gR2> insert into duplicate_demo (id, geometry) values (7,
2 sdo_geometry(2003,81989,null, sdo_elem_info_array(1,1003,1),
3 sdo_ordinate_array(601706,301321, 602554,301321, 601744,302032, 602612,302028, 601790,301429, 601706,301321)));
1 row created.
jot_test@11gR2>
jot_test@11gR2> insert into duplicate_demo (id, geometry) values (8,
2 sdo_geometry(2003,81989,null, sdo_elem_info_array(1,1003,1),
3 sdo_ordinate_array(601706,301321, 602554,301321, 601744,302032, 602612,302028, 601790,301429, 601706,301321)));
1 row created.
jot_test@11gR2>
jot_test@11gR2> commit;
Commit complete.
jot_test@11gR2>
jot_test@11gR2> -- Identify which rows duplicate each other
jot_test@11gR2> select /*+ ORDERED */ b.id, a.id
2 from duplicate_demo a, duplicate_demo b
3 where sdo_equal (a.geometry, b.geometry) = 'TRUE'
4 and a.id != b.id
5 order by 1,2;
ID ID
1 2
1 3
2 1
2 3
3 1
3 2
4 5
4 6
5 4
5 6
6 4
6 5
7 8
8 7
14 rows selected.
jot_test@11gR2>
jot_test@11gR2> -- Now delete the duplicates
jot_test@11gR2> delete from duplicate_demo a where rowid > (
2 select /*+ ORDERED */ min(rowid)
3 from duplicate_demo b
4 where sdo_equal (b.geometry, a.geometry) = 'TRUE');
5 rows deleted.Regards
John
Maybe you are looking for
-
Hi there Guys i'm a very new labview user (PhD student), my project is about ( design and implementation of a high speed-yet sophisticated system using Labview environment then install this project's code (using Labview FPGA module) onto Altera-made
-
Add an existing website to Muse
Hello, I am new to Muse, however, I build sites in Dreamweaver and WordPress so not new to building sites. How do I add an existing website to Muse to work on? Site in question was built by someone and we have access to all the files but not sure how
-
Can we schedule the receiver communication channel ?
Dear all , I have a scenario of IDOC -> XI -> flat file The requirement is the receiver file channel should start after every 10 min and all the files which are coverted from idocs will then go to the destination folder Is it possible to schedule
-
I have plug and external scsi cd rom in my machine and i need to mount it but i am unable to found it in /dev. Where do I get it.
-
Update GOITEM-ERFMG in MIGO using user exit in SAP ECC 6.0
Dear Gurus, Kindly help me to solve the issue. We have requrement to update GOITEM-ERFMG field at the time of MIGO based on text input in GOHEAD-BKTXT as selection criteria in selection query in Z table. We try to acheive this using different enhance