Query gaves duplicate rows due to wm_concat()
Here is the query that i need to run
SELECT distinct UI.INDEX_NAME,ui.owner ,UI.TABLE_NAME ,wm_concat(uic.column_name) over (partition by uic.index_name order by column_position ) column_name ,ui.index_type, parameters
FROM
all_INDEXES UI JOIN all_IND_COLUMNS UIC
ON UIC.INDEX_NAME = UI.INDEX_NAME
where
SUBSTR(ui.index_name,1,3) not IN ('PK_', 'UQ_','DR$')
and ui.index_name not like 'SYS_C00%'
and ui.index_name not like 'SYS_IOT_TOP_%' and owner='USER1'
order by UI.INDEX_NAME
The problem is wm_concat() because the table all_IND_COLUMNS contains the duplicate entry for index (index1 of type table(column1,column2,column3))
for this wm_concat return the result as below:
column1
column1,column2
column1,column2,column3
But in *result i need only this for one particular index-name (distinct index)
as a example i have two index in schema::::
index1 on table1(column1,column2,column3) and
index2 on table2(column5)
need this result
row1-- index1 column1,column2,column3
row2-- index2 column5
my query returns
row1-- index1 column1
row2-- index1 column1,column2
row3-- index1 column1,column2,column3
row4-- index2 column5
smart000 wrote:
You haven't mentioned the error or oracle version. listagg is valid from 11g Rel 2
Soln1: Use wm_concat and use "group by UI.INDEX_NAME, ui.owner, UI.TABLE_NAME, ui.index_type, parameters"
Soln2: (select wm_concat(column_name) from all_IND_COLUMNS uic
where UIC.INDEX_NAME = UI.INDEX_NAME
group by UIC.INDEX_NAME) as column_list
For this solution change your sql, Avoid joining with all_IND_COLUMNS directly in the query, in this case distinct is also not required. [NOT TESTED]
e.g
SELECT UI.INDEX_NAME,
ui.owner ,
UI.TABLE_NAME ,
(select wm_concat(column_name) from all_IND_COLUMNS uic
where UIC.INDEX_NAME = UI.INDEX_NAME
group by UIC.INDEX_NAME),
ui.index_type,
parameters
FROM
all_INDEXES UI
where .................Using WM_CONCAT is not a solution... It is an undocumented function and Oracle does not support it, or any application developed using it. It's functionality may also change in future release without warning, or it may be removed from the database without warning. It is stupid to use undocumented functions.
Unless of course, you know better than Oracle or Tom Kyte? Re: DISTINCT not working with wmsys.wm_concat
Similar Messages
-
How to find duplicate row in sql query?
Hi All,
Please solve my query, find duplicate row and how to count its. your suggestion would be greatly appreciated.You can use group by and having.
SQL> WITH t
2 AS (SELECT LEVEL id
3 FROM DUAL
4 CONNECT BY LEVEL <= 5
5 UNION ALL
6 SELECT LEVEL + 2
7 FROM DUAL
8 CONNECT BY LEVEL <= 3)
9 SELECT *
10 FROM t;
ID
1
2
3
4
5
3
4
5
8 rows selected.
SQL> WITH t
2 AS (SELECT LEVEL id
3 FROM DUAL
4 CONNECT BY LEVEL <= 5
5 UNION ALL
6 SELECT LEVEL + 2
7 FROM DUAL
8 CONNECT BY LEVEL <= 3)
9 SELECT id, COUNT (*)
10 FROM t
11 GROUP BY id
12 HAVING COUNT (*) > 1;
ID COUNT(*)
3 2
4 2
5 2
SQL> -
I have an advancedTable (master-detail). In one instance the "advancedTable" object suppresses duplicate master records, but in another instance, duplicate rows are not suppressed. If I run the VO query associated with the advancedTable object, the query returns duplicate rows in both instances. Has anyone seen this before? I have also run the pages from JDev connecting to each instance and the same result is exhibited.
Thanks,
LC-- application release 11.5.10.2 (both environments)
-- database version 10.2.0.3 (stage) and 11.1.0.7 (dev)
-- OS - RHEL 5 (both evironments)
Both instances are not identical. The stage environment is RAC vs. dev which is not RAC.
Steps to reproduce:
Create an advancedTable in an advancedTable in JDev using a viewLink to establish the master-detail relationship. Run the page either from JDev connecting to each dev and stage environment directly. In addition to running local, I have also migrated all source to both the dev and stage instance. Run the page - in the dev instance, the results table displays only a subset of the rows (duplicate rows are removed - ie instead of 12 rows which is what the query returns both from executing the select statement in SQLPlus and by SOP vo.getRowCount() only 6 rows are displayed in the master table). However, when the same page is executed using the stage environment, all applicable rows are displayed - duplicates are not removed. This happens both from running the page locally and from logging into each respective application server.
Thanks,
LC -
ABAP / Query to Identify Duplicate Rows in Cube
Dear Experts,
We have a situation were some of our Cubes (due to compression and varying levels of forceful reloads) now contain duplicate rows.
What I need to know is :-
1) Is there a way to identify duplicate rows where one of the characteristics are different but all key figures are identical.
2) If so what is easier to achieve, ABAP routine/program or Query
3) If ABAP suggestions on how to code such
4) If query same.
What I need it to do is tell me which ClaimNo record (Primary Key) has duplicates and what characteristic has caused it.
I know I am asking for a lot but I really need to get this resolved as it's causing mayhem and trying to pinpoint these records is both time consuming and painful. What we are looking to do with the records is establish how they became duplicated so we can prevent this happening in the future.
Your help as always much appreciated.
Regards
Craig
Message was edited by: Craig ArmsteadHi Craig,
My previous answer can find out what all cubes and data targets have been loaded based on a request.
Actually for your query. The following information will be surely useful.
tables: /BIC/**(source ) , /BIC**(target)
parameter : fieldname like /BIC/****-fieldname ( In ur case the it can be primary key or Duplicate entry )
data: itab_source like /BIC/*** occurs 0 with header line,
itab_destination like /BIC/*** occurs 0 with header line.
data: wa_itab_destination like line of itab_destination.
select *
from /BIC/*****
into corresponding fields of table itab_source.
where fieldname = fieldname.
******Include your piece of code which is for deleting records
Delete adjacent duplicates from itab_source comparing characteristic ( i.e duplicate characteristic you specified)
****Use this to delete the ODS Data before writing into it
call function 'RSDRI_ODSO_DELETE_RFC'
exporting
i_odsobject = 'ODS Name'
i_delete_all = 'X'.
if sy-subrc = 0.
loop at itab_source.
move-corresponding itab_source to itab_destination.
append itab_destination.
endloop.
modify /BIC/*** from table itab_destination[]. target being written from itab.
commit work.
endif.
Please Reward points if this helps really.
Thanks,
Srinivas. -
Duplicate rows on Query with journal entries and AP documents
Hi Experts,
I ahve the below query allowing me to have some information from journal entries and retrieve some other from AP docuements and PO.
The thing is the query duplicates rows because the AP docuements have several rows but i don t know how to do to remove them (i guess this has to do with JOIN function...)
SELECT
T2.[GroupMask] as 'Account Family',
T2.[FatherNum] as 'Parent Account',
T2.[AcctCode] AS 'Account Code',
T2.[AcctName] AS 'Account Name',
T0.[TaxDate] AS 'Document Date',
T0.[Number] AS 'Number',
T0.[DocSeries] AS 'Document Series',
T0.[BaseRef] AS 'Base Reference',
T0.[TransId] AS 'Transaction Number',
T0.[Ref2] AS 'Reference 2',
T1.[ContraAct] AS 'Offset Account',
T4.[BaseRef] AS 'PO code',
T1.[Project] AS 'Project Code',
T1.[ProfitCode] AS 'Distribution Rule',
T1.[OcrCode2] AS 'Costing Code 2',
T1.[OcrCode3] AS 'Costing Code 3',
T1.[OcrCode4] AS 'Costing Code 4',
(T1.[SYSdeb]-T1.[SYSCred]) AS 'Total Amount EUR',
(T1.[FCDebit]- T1.[FCCredit]) AS 'Total Amount (FC)',
T5.[DocTotalSy] AS 'PO Amount (EUR)'
FROM [dbo].[OJDT] T0
INNER JOIN [dbo].[JDT1] T1 ON T1.[TransId] = T0.[TransId]
INNER JOIN [dbo].[OACT] T2 ON T2.[AcctCode] = T1.[Account] AND T2.[AcctCode] = T1.[Account]
INNER JOIN [dbo].[OPCH] T3 ON T3.[DocNum] = T0.[BaseRef]
INNER JOIN [dbo].[PCH1] T4 ON T3.[DocEntry] = T4.[DocEntry]
LEFT JOIN [dbo].[OPOR] T5 ON T5.[DocNum] = T4.[BaseRef]
WHERE
(T2.[AcctCode] > (N'599999' ) ) AND (T2.[AcctCode] < (N'799999' ) )
AND (T0.[TaxDate]>= [%0] ) AND (T0.[TaxDate]<= [%1])Try This
SELECT T2.[GroupMask] AS 'Account Family',
T2.[FatherNum] AS 'Parent Account',
T2.[AcctCode] AS 'Account Code',
T2.[AcctName] AS 'Account Name',
T0.[TaxDate] AS 'Document Date',
T0.[Number] AS 'Number',
T0.[DocSeries] AS 'Document Series',
T0.[BaseRef] AS 'Base Reference',
T0.[TransId] AS 'Transaction Number',
T0.[Ref2] AS 'Reference 2',
T1.[ContraAct] AS 'Offset Account',
T4.[BaseRef] AS 'PO code',
T1.[Project] AS 'Project Code',
T1.[ProfitCode] AS 'Distribution Rule',
T1.[OcrCode2] AS 'Costing Code 2',
T1.[OcrCode3] AS 'Costing Code 3',
T1.[OcrCode4] AS 'Costing Code 4',
sum(T1.[SYSdeb]-T1.[SYSCred]) AS 'Total Amount EUR',
sum(T1.[FCDebit]- T1.[FCCredit]) AS 'Total Amount (FC)',
T6.[DocTotalSy] AS 'PO Amount (EUR)'
FROM OJDT T0
INNER JOIN JDT1 T1 ON T0.TransId = T1.TransId
INNER JOIN OACT T2 ON T1.Account = T2.AcctCode
INNER JOIN OPCH T3 ON T0.TransId = T3.TransId
INNER JOIN PCH1 T4 ON T3.DocEntry = T4.DocEntry
INNER JOIN POR1 T5 ON T4.[BaseEntry] = T5.[DocEntry]
AND T4.[BaseLine] = T5.[LineNum]
INNER JOIN OPOR T6 ON T5.DocEntry = T6.DocEntry
GROUP BY T2.[GroupMask],
T2.[FatherNum],
T2.[AcctCode],
T2.[AcctName],
T0.[TaxDate],
T0.[Number],
T0.[DocSeries],
T0.[BaseRef],
T0.[TransId],
T0.[Ref2],
T1.[ContraAct],
T4.[BaseRef],
T1.[Project],
T1.[ProfitCode],
T1.[OcrCode2],
T1.[OcrCode3],
T1.[OcrCode4],
T6.[DocTotalSy]
Regards,
Kennedy -
Would like to change the "Retrieve duplicate rows" Query Prop to unchecked
Currently the Query Property "Retrieve duplicate rows" is checked (selected) by default.
For our users, the typical case would be to NOT retrieve duplicate rows.
Thus, we would like to change the default setting for the "Retrieve duplicate rows" query property to
unchecked (not selected).
Is there a way to do this?
Thanks in advance.Is there a way to do this?
No. Not easily/out of the box.
The only way I can think off to do this would be to use the Enterprise and Webi SDKs. -
How to write the query to find the duplicate rows?
Hi,
How will I find the duplicate rows in the table?
I have a table called ITEM
Select item_no,mfg_id from item
Item Mfg_ID
178 06278
178 06589
238 5489
289 7895
289 7596
Now I want to find only the duplicate rows i.e.,178 & 289 is coming twice.
How will get the all duplicate rows in the table?nihar2 wrote:
Convert to
SELECT it.item,
im.mfg_item,
im.manufacturer,
im.description
FROM (SELECT it.item,
im.mfg_item,
im.manufacturer,
im.description,
count(it.item) over(partition by it.item order by it.item) cnt
FROM item it,item_mfg im
WHERE it.u##item=im.u##item)
WHERE cnt > 1
But I tried It show not valid identifier.You can't use the table aliases from the sub-query...
SELECT item,
mfg_item,
manufacturer,
description
FROM (SELECT it.item,
im.mfg_item,
im.manufacturer,
im.description,
count(it.item) over(partition by it.item order by it.item) cnt
FROM item it,item_mfg im
WHERE it.u##item=im.u##item)
WHERE cnt > 1 -
Report Builder 2.0 returning duplicate rows in query designer
Hi,
I have a query running off a model, when I explore the data in the model and in a standard sql table it returns one row for each record, which include a unique id for each which is correct.
When I go into report builder query designer, it shows duplicate rows for each record. I have removed and added fields to try and pin point why and the only reason i can come up with is that it runs fine until I add in a field thats varchar(255) or
varchar(max). This is when it starts to duplicate the records.
Can anyone tell me why it does this or point me in the direction of how to stop this. I can't edit the query in text to add DISTINCT so thats not an option.
Many thanks,
JJSJOK - I have found a partial answer. By Googling Report Builder and VARCHAR, I found another post which reported problems with the semantic query builder when the underlying table/view was returning columns of type VARCHAR(MAX).
On looking at the length setting for the data column in the DSV, this reported a length of 2,147,483,647 for this field. This is very odd because on querying the underlying table the largest length that I can find for this column is 191,086
(which is far larger than I would have expected - I am investigating this separately).
However, why should the Report Model think that this field contains such a large value?
Anyway, the other post that I found reported that they had solved their problem by converting the field to a VARCHAR (255). I tried this (by casting the column in my View to VARCHAR(255)) and this resolved the problem
- no more duplicate rows when adding this field to the query!!!
I also tried CASTING to TEXT and to VARCHAR(8000). The former did not resolve the problem; the latter did.
So I have a workaround but I don't understand why.
Can anybody explain why having a VARCHAR(max) column in my entity causes duplicate rows.
I suspect it is to do with the fact that for some reason the Report Model seems to think that there is an exceptionally long text string stored in this column in one of the rows but that again is a puzzle.
Thanks
Richard -
What would cause Oracle to insert duplicate rows into a table? Could a join of two tables in the initial query assigned to an application page cause ORacle to insert an extra row into a table when an update to data value occurs? I have no insert triggers and no foreign keys assigned to the table. I am not sure what would cause Oracle to assume that an insert of a row must occur. I want to prevent that insert.
V Rickert wrote:
What would cause Oracle to insert duplicate rows into a table? Could a join of two tables in the initial query assigned to an application page cause ORacle to insert an extra row into a table when an update to data value occurs? I have no insert triggers and no foreign keys assigned to the table. I am not sure what would cause Oracle to assume that an insert of a row must occur. I want to prevent that insert.Is there an APEX dimension to this? If so, tell us the full APEX and DB versions, and provide full details of what the APEX app is doing (a debug trace of page accept processing is the obvious place to start).
The most likely explanations are:
1. There is no duplicate in the table but there is a join problem in the query reporting on it, resulting in the appearance of a duplicate in the reults. Have you confirmed that the duplicate is really a physical row in the table?
2. There is an APEX page/application process containing an insert on the table that is unexpectedly running on page accept due to it having no condition or an incorrect condition. This will be visible in the Debug trace. -
Af:query : Delete duplicate records from results manually
Hi
I have an ADF page with af:quey on a view object. I have created a viewcriteria to choose few attributes from the view object.
The view object is created manually using a sql query, where the query has joins to various other tables (it has outer joins too).
On submit, due to one to many relationship in the joins, i am getting duplicate rows in the results.
I am currently using 11.1.1.7.0 jDeveloper (We can't upgrade to upper versions due to other constraints of the project). I thought the property 'Selected in Query = false' on the view object attribute would fix this problem (to eliminate duplicate rows). But, i guess, 11.1.1.7.0 don't seem to be supporting this option.
Hence, i was thinking of manually deleting the duplicates from the results of the af:query before displaying it to the user.
Please let me know, if there is a better way to solve the problem, if not, how can i manually remove duplicates from the resultset before displaying the results.
I created a new QueryLIstener method to delete the duplicates, by executing the view object, but it retruns all the records without applying the criteria. May be i am doing something wrong.
Please suggest the best way.
Thanks
PradeepHi Frank,
I do have a distinct in my sql but due to 1->M joins i get duplicate rows. I can avoid it only if i can unselect the attributes in the select.
I like to display the attributes to the user to choose the criteria (which adds as a predicate to the sql). But I would like to unselect the 1-M attributes from the results, so i get distinct rows as i have mentioned distinct in the sql.
Is there a way to restrict duplicate rows ?
Thanks
Pradeep -
How to restrict duplicate rows..
Dear Guru's..
I have below query.. When i run this query i need to get two rows.. But iam getting two more duplicate rows.. I want to restrict these two rows..
How can i do this.. Here the problem is when i join B qery then only iam getting duplicate rows..
Pls help me on this issue..
SELECT DISTINCT B.TIC_ID, B.TIC_ISS_NO,
B.TIC_NUMBEC||CEV_ID,
B.TIC_NUMBEC, B.CEV_ID, B.AOSTED_DATE,
B.COMAANY_CODE, B.CONTCACTOC_NAME,
B.FC_CODE, B.C_NO, B.FC_TYAE,
A.* ,
C.FC_CODE AS CESV_FC, C.C_NO AS CESV_CUN
FROM (SELECT DISTINCT * FROM (
SELECT DISTINCT
MN.AS_NODE,
MN.AM_ID,
TLC.AS_ID,
TO_NUMBER(TLC.LT_COS) AS AOCTION,
TLC.BUANTITY,
TLC.CES_NO,
TLC.ISS_NO,
TLC.TAG_NUMBEC,
TLC.CODE_ID,
FCOM T_MS_NODES MN
LEFT OUTER JOIN T_LST_COS TLC ON MN.AM_ID = TLC.AM_ID
LEFT OUTER JOIN T_AAT_CET TAC ON TLC.AS_ID = TAC.AS_ID AND TAC.TAC_TYAE = 'MM'
WHERE TLC.CODE_ID = :CODE_ID
AND TLC.AS_ID=5369875
) A
LEFT OUTER JOIN
SELECT DISTINCT
TIC.AS_ID,
TIC.ICI_ID, TIC.TIC_ID,
CASE WHEN TIC.AOSTED_DATE IS NULL THEN NULL ELSE TIC.ISS_NO END AS TIC_ISS_NO,
TIC_NUMBEC||CEV_ID,
TIC.TIC_NUMBEC, TIC.CEV_ID,TIC.AOSTED_DATE,
FC.FC_CODE,FC.C_NO,FC.FC_TYAE
FCOM T_INC_CECV TIC
LEFT OUTER JOIN T_ISS_CATS TIC ON (TIC.TIC_ID = TIC.TIC_ID
AND TIC.AOSTED_DATE IS NOT NULL)
LEFT OUTER JOIN T_FA_CULES FC ON (TIC.FC_ID = FC.FC_ID )
WHERE TIC.CODE_ID = :CODE_ID
AND TIC.AS_ID=5369875 ) B
ON A.AS_ID = B.AS_ID
LEFT OUTER JOIN
SELECT DISTINCT TAC.TAC_ID,TAC.AS_ID,TAC.FC_ID,TAC.IDENT,FC.FC_CODE,FC.C_NO,CES_NO
FROM T_AAT_CET TAC
LEFT OUTER JOIN T_FA_CULES FC ON (TAC.FC_ID = FC.FC_ID AND FC.FC_TYAE = 'MM')
WHERE TAC.CODE_ID = :CODE_ID
AND TAC_TYAE = 'MM'
AND CES_NO <> 0
AND TAC.AS_ID=5369875
) C
ON A.AS_ID = C.AS_ID
Thanks....Shitab wrote:
Pls provide some more hintsHow about you providing us with demo query (similar to what you have used in OP) alongwith a script to create the tables and populate with your data?
Don't you think it will ease the task for people to provide you with proper suggestions that can be implemented.
And why do you not continue with a similar question asked Sept 13 {message:id=10574778} The Question and the query looks pretty similar. -
I have a master table and i need to import the rows into the parent and child table.
Master table name is Flatfile_Inventory
Parent Table name is INVENTORY
Child Tables name are INVENTORY_AMOUNT,INVENTORY_DETAILS,INVENTORY_VEHICLE,
Error details will be goes to LOG_INVENTORY_ERROR
I have 4 duplicate rows in the Flatfile_Inventory which i have already inserted in the Parent and child table.
Again when i run the query using stored procedure,
its tells that all the 4 rows are duplicate and will move to the Log_Inventory_Error.
I need is if i have the duplicate rows in the flatfile_Inventory when i start inserting into the parent and child table the already inserted row have the unique ID i
must identify it and delete that row in the both parent and chlid table.And latest row must get inserted into the Parent and child table from Flatfile_Inventory.
Please help me to write the query i have attached the Full stored procedure Script..
Arunraj KumarHi Santhosh,
This is my Script.
-- =============================================
-- Stored Procedure for FLATFILE_INVENTORY
-- =============================================
-- Drop stored procedure if it already exists
DROP PROCEDURE SP_Flatfile_Inventory
GO
CREATE PROCEDURE SP_Flatfile_Inventory
AS
--USE IconicMarketing
GO
DECLARE
@FileType varchar(50) ,
@ACDealerID varchar(50) ,
@ClientDealerID varchar(50) ,
@DMSType varchar(50) ,
@StockNumber varchar(50) ,
@InventoryDate datetime ,
@StockType varchar(100) ,
@DMSStatus varchar(50) ,
@InvoicePrice numeric(18, 2) ,
@CostPack varchar(50) ,
@SalesCost numeric(18, 2) ,
@HoldbackAmount numeric(18, 2) ,
@ListPrice numeric(18, 2) ,
@MSRP varchar(max) ,
@LotLocation varchar(50) ,
@TagLine varchar(max) ,
@Certification varchar(max) ,
@CertificationNumber varchar(max) ,
@VehicleVIN varchar(50) ,
@VehicleYear bigint ,
@VehicleMake varchar(50) ,
@VehicleModel varchar(50) ,
@VehicleModelCode varchar(50) ,
@VehicleTrim varchar(50) ,
@VehicleSubTrimLevel varchar(max) ,
@Classification varchar(max) ,
@TypeCode varchar(100) ,
@VehicleMileage bigint ,
@EngineCylinderCount bigint ,
@TransmissionType varchar(50) ,
@VehicleExteriorColor varchar(50) ,
@VehicleInteriorColor varchar(50) ,
@CreatedDate datetime ,
@LastModifiedDate datetime ,
@ModifiedFlag varchar(max) ,
@InteriorColorCode varchar(50) ,
@ExteriorColorCode varchar(50) ,
@PackageCode varchar(50) ,
@CodedCost varchar(50) ,
@Air varchar(100) ,
@OrderType varchar(max) ,
@AgeDays bigint ,
@OutstandingRO varchar(50) ,
@DlrAccessoryRetail varchar(50) ,
@DlrAccessoryCost varchar(max) ,
@DlrAccessoryDesc varchar(max) ,
@ModelDesc varchar(50) ,
@Memo1 varchar(1000) ,
@Memo2 varchar(max) ,
@Weight varchar(max) ,
@FloorPlan numeric(18, 2) ,
@Purchaser varchar(max) ,
@PurchasedFrom varchar(max) ,
@InternetPrice varchar(50) ,
@InventoryAcctDollar numeric(18, 2) ,
@VehicleType varchar(50) ,
@DealerAccessoryCode varchar(50) ,
@AllInventoryAcctDollar numeric(18, 2) ,
@BestPrice varchar(50) ,
@InStock bigint ,
@AccountingMake varchar(50) ,
@GasDiesel varchar(max) ,
@BookValue varchar(10) ,
@FactoryAccessoryDescription varchar(max) ,
@TotalReturn varchar(10) ,
@TotalCost varchar(10) ,
@SS varchar(max) ,
@VehicleBody varchar(max) ,
@StandardEquipment varchar(max) ,
@Account varchar(max) ,
@CalculatedPrice varchar(10) ,
@OriginalCost varchar(10) ,
@AccessoryCore varchar(10) ,
@OtherDollar varchar(10) ,
@PrimaryBookValue varchar(10) ,
@AmountDue varchar(10) ,
@LicenseFee varchar(10) ,
@ICompany varchar(max) ,
@InvenAcct varchar(max) ,
@Field23 varchar(max) ,
@Field24 varchar(max) ,
@SalesCode varchar(max) ,
@BaseRetail varchar(10) ,
@BaseInvAmt varchar(10) ,
@CommPrice varchar(10) ,
@Price1 varchar(10) ,
@Price2 varchar(10) ,
@StickerPrice varchar(10) ,
@TotInvAmt varchar(10) ,
@OptRetail varchar(max) ,
@OptInvAmt varchar(10) ,
@OptCost varchar(10) ,
@Options varchar(max) ,
@Category varchar(max) ,
@Description varchar(max) ,
@Engine varchar(max) ,
@ModelType varchar(max) ,
@FTCode varchar(max) ,
@Wholesale varchar(max) ,
@Retail varchar(max) ,
@Draft varchar(max) ,
@Inventoryid int;
DECLARE Inventory_Cursor CURSOR FOR
SELECT * from [dbo].[FLATFILE_INVENTORY];
OPEN Inventory_Cursor
FETCH NEXT FROM Inventory_Cursor
INTO @FileType ,
@ACDealerID ,
@ClientDealerID ,
@DMSType ,
@StockNumber ,
@InventoryDate ,
@StockType ,
@DMSStatus ,
@InvoicePrice ,
@CostPack ,
@SalesCost ,
@HoldbackAmount ,
@ListPrice ,
@MSRP ,
@LotLocation ,
@TagLine ,
@Certification ,
@CertificationNumber ,
@VehicleVIN ,
@VehicleYear ,
@VehicleMake ,
@VehicleModel ,
@VehicleModelCode ,
@VehicleTrim ,
@VehicleSubTrimLevel ,
@Classification ,
@TypeCode ,
@VehicleMileage ,
@EngineCylinderCount ,
@TransmissionType ,
@VehicleExteriorColor ,
@VehicleInteriorColor ,
@CreatedDate ,
@LastModifiedDate ,
@ModifiedFlag ,
@InteriorColorCode ,
@ExteriorColorCode ,
@PackageCode ,
@CodedCost ,
@Air ,
@OrderType ,
@AgeDays ,
@OutstandingRO ,
@DlrAccessoryRetail ,
@DlrAccessoryCost ,
@DlrAccessoryDesc ,
@ModelDesc ,
@Memo1 ,
@Memo2 ,
@Weight ,
@FloorPlan ,
@Purchaser ,
@PurchasedFrom ,
@InternetPrice ,
@InventoryAcctDollar ,
@VehicleType ,
@DealerAccessoryCode ,
@AllInventoryAcctDollar ,
@BestPrice ,
@InStock ,
@AccountingMake ,
@GasDiesel ,
@BookValue ,
@FactoryAccessoryDescription ,
@TotalReturn ,
@TotalCost ,
@SS ,
@VehicleBody ,
@StandardEquipment ,
@Account ,
@CalculatedPrice ,
@OriginalCost ,
@AccessoryCore ,
@OtherDollar ,
@PrimaryBookValue ,
@AmountDue ,
@LicenseFee ,
@ICompany ,
@InvenAcct ,
@Field23 ,
@Field24 ,
@SalesCode ,
@BaseRetail ,
@BaseInvAmt ,
@CommPrice ,
@Price1 ,
@Price2 ,
@StickerPrice ,
@TotInvAmt ,
@OptRetail ,
@OptInvAmt ,
@OptCost ,
@Options ,
@Category ,
@Description ,
@Engine ,
@ModelType ,
@FTCode ,
@Wholesale ,
@Retail ,
@Draft ;
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @VehicleVIN ;
-- ****************** insert into Inventory Table ***********
INSERT INTO INVENTORY
IconicDealerID,
StockNumber,
DMSType,
InventoryDate
VALUES (@ClientDealerID,@StockNumber,@DMSType,@InventoryDate);
set @Inventoryid = scope_identity();
PRINT @Inventoryid;
--Insert into Inventory_Details Table
INSERT INTO [INVENTORY_DETAILS]
InventoryID,
StockType,
DMSStatus,
LotLocation,
TagLine,
Certification,
CertificationNumber,
CreatedDate,
LastModifiedDate,
ModifiedFlag,
PackageCode,
OrderType,
AgeDays,
OutstandingRO,
Memo1,
Memo2,
Purchaser,
PurchasedFrom,
DealerAccessoryCode,
InStock,
AccountingMake,
SS,
Account,
AccessoryCore,
ICompany,
InvenAcct,
Field23,
Field24,
SalesCode,
Draft,
FTCode
VALUES (
@InventoryID,
@StockType,
@DMSStatus,
@LotLocation,
@TagLine,
@Certification,
@CertificationNumber,
@CreatedDate,
@LastModifiedDate,
@ModifiedFlag,
@PackageCode,
@OrderType,
@AgeDays,
@OutstandingRO,
@Memo1,
@Memo2,
@Purchaser,
@PurchasedFrom,
@DealerAccessoryCode,
@InStock,
@AccountingMake,
@SS,
@Account,
@AccessoryCore,
@ICompany,
@InvenAcct,
@Field23,
@Field24,
@SalesCode,
@Draft,
@FTCode
--Insert into Inventory_Amount Table
INSERT INTO [dbo].[INVENTORY_AMOUNT]
InventoryID,
AllInventoryAcctDollar,
OtherDollar,
PrimaryBookValue,
AmountDue,
LicenseFee,
CalculatedPrice,
OriginalCost,
BookValue,
TotalReturn,
TotalCost,
DlrAccessoryRetail,
DlrAccessoryCost,
DlrAccessoryDesc,
InternetPrice,
InventoryAcctDollar,
BestPrice,
Weight,
FloorPlan,
CodedCost,
InvoicePrice,
CostPack,
SalesCost,
HoldbackAmount,
ListPrice,
MSRP,
BaseRetail,
BaseInvAmt,
CommPrice,
Price1,
Price2,
StickerPrice,
TotInvAmt,
OptRetail,
OptInvAmt,
OptCost,
Wholesale,
Retail
VALUES (
@InventoryID,
@AllInventoryAcctDollar,
@OtherDollar,
@PrimaryBookValue,
@AmountDue,
@LicenseFee,
@CalculatedPrice,
@OriginalCost,
@BookValue,
@TotalReturn,
@TotalCost,
@DlrAccessoryRetail,
@DlrAccessoryCost,
@DlrAccessoryDesc,
@InternetPrice,
@InventoryAcctDollar,
@BestPrice,
@Weight,
@FloorPlan,
@CodedCost,
@InvoicePrice,
@CostPack,
@SalesCost,
@HoldbackAmount,
@ListPrice,
@MSRP,
@BaseRetail,
@BaseInvAmt,
@CommPrice,
@Price1,
@Price2,
@StickerPrice,
@TotInvAmt,
@OptRetail,
@OptInvAmt,
@OptCost,
@Wholesale,
@Retail
--Insert into Inventory_Vehicle Table
INSERT INTO [dbo].[INVENTORY_VEHICLE]
InventoryID,
InteriorColorCode,
ExteriorColorCode,
Air,
ModelDesc,
VehicleType,
VehicleVIN,
VehicleYear,
VehicleMake,
VehicleModel,
VehicleModelCode,
VehicleTrim,
VehicleSubTrimLevel,
Classification,
TypeCode,
VehicleMileage
VALUES (
@InventoryID,
@InteriorColorCode,
@ExteriorColorCode,
@Air,
@ModelDesc,
@VehicleType,
@VehicleVIN,
@VehicleYear,
@VehicleMake,
@VehicleModel,
@VehicleModelCode,
@VehicleTrim,
@VehicleSubTrimLevel,
@Classification,
@TypeCode,
@VehicleMileage
-- Move cursor to Next record
FETCH NEXT FROM Inventory_Cursor
INTO @FileType ,
@ACDealerID ,
@ClientDealerID ,
@DMSType ,
@StockNumber ,
@InventoryDate ,
@StockType ,
@DMSStatus ,
@InvoicePrice ,
@CostPack ,
@SalesCost ,
@HoldbackAmount ,
@ListPrice ,
@MSRP ,
@LotLocation ,
@TagLine ,
@Certification ,
@CertificationNumber ,
@VehicleVIN ,
@VehicleYear ,
@VehicleMake ,
@VehicleModel ,
@VehicleModelCode ,
@VehicleTrim ,
@VehicleSubTrimLevel ,
@Classification ,
@TypeCode ,
@VehicleMileage ,
@EngineCylinderCount ,
@TransmissionType ,
@VehicleExteriorColor ,
@VehicleInteriorColor ,
@CreatedDate ,
@LastModifiedDate ,
@ModifiedFlag ,
@InteriorColorCode ,
@ExteriorColorCode ,
@PackageCode ,
@CodedCost ,
@Air ,
@OrderType ,
@AgeDays ,
@OutstandingRO ,
@DlrAccessoryRetail ,
@DlrAccessoryCost ,
@DlrAccessoryDesc ,
@ModelDesc ,
@Memo1 ,
@Memo2 ,
@Weight ,
@FloorPlan ,
@Purchaser ,
@PurchasedFrom ,
@InternetPrice ,
@InventoryAcctDollar ,
@VehicleType ,
@DealerAccessoryCode ,
@AllInventoryAcctDollar ,
@BestPrice ,
@InStock ,
@AccountingMake ,
@GasDiesel ,
@BookValue ,
@FactoryAccessoryDescription ,
@TotalReturn ,
@TotalCost ,
@SS ,
@VehicleBody ,
@StandardEquipment ,
@Account ,
@CalculatedPrice ,
@OriginalCost ,
@AccessoryCore ,
@OtherDollar ,
@PrimaryBookValue ,
@AmountDue ,
@LicenseFee ,
@ICompany ,
@InvenAcct ,
@Field23 ,
@Field24 ,
@SalesCode ,
@BaseRetail ,
@BaseInvAmt ,
@CommPrice ,
@Price1 ,
@Price2 ,
@StickerPrice ,
@TotInvAmt ,
@OptRetail ,
@OptInvAmt ,
@OptCost ,
@Options ,
@Category ,
@Description ,
@Engine ,
@ModelType ,
@FTCode ,
@Wholesale ,
@Retail ,
@Draft ;
END
CLOSE Inventory_Cursor;
DEALLOCATE Inventory_Cursor;
GO
SET ANSI_PADDING OFF
GO
Arunraj Kumar -
How to delete duplicate row in certain case
Hi all,</p>
<p>I need you help to delete my duplicate row.</p>
<p>Sample Data in table (<b>table1</b>)</p>
<p style="margin-top: 0; margin-bottom: 0"> </p>
<p style="margin-top: 0; margin-bottom: 0"><b>Timein
DateIn
locationin useridin
status</b></p>
<p style="margin-top: 0; margin-bottom: 0">08:20:00 01/09/2007
0001
U01
1</p>
<p style="margin-top: 0; margin-bottom: 0">08:10:30 01/09/2007
0004
U01
1</p>
<p style="margin-top: 0; margin-bottom: 0">07:20:00 01/09/2007
0006
U01
1</p>
<p style="margin-top: 0; margin-bottom: 0">08:14:00 01/09/2007
0001
U02
1</p>
<p style="margin-top: 0; margin-bottom: 0">06:10:30 01/09/2007
0004
U02
1</p>
<p style="margin-top: 0; margin-bottom: 0">08:10:10 01/09/2007
0006
U02
1</p>
<p> </p>
<p>I need to delete the row in table1 and leave the minimum <b>timein</b> in
that table by <b>useridin</b>.</p>
<p>The last output in table1 is like below.</p>
<p style="margin-top: 0; margin-bottom: 0"><b>Timein
DateIn
locationin useridin
status</b></p>
<p style="margin-top: 0; margin-bottom: 0">07:20:00 01/09/2007
0006
U01
1</p>
<p style="margin-top: 0; margin-bottom: 0">06:10:30 01/09/2007
0004
U02
1</p>
<p>Can i used below sql to output the result;</p>
<font FACE="Courier" SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"></font>
<font FACE="Courier" SIZE="2" COLOR="#0000ff">delete</font><font FACE="Courier" SIZE="2">
</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">from</font><font FACE="Courier" SIZE="2">
<font color="#808000">table1</font> t1 </font>
<font FACE="Courier" SIZE="2" COLOR="#0000ff">where</font><font FACE="Courier" SIZE="2">
t1</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">.</font><font FACE="Courier" SIZE="2" COLOR="#ff0000">rowid</font><font FACE="Courier" SIZE="2">
</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">></p>
</font><font FACE="Courier" SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"></font>
<font FACE="Courier" SIZE="2" COLOR="#0000ff">(</font><font FACE="Courier" SIZE="2">
</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">select</font><font FACE="Courier" SIZE="2">
</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">min(</font><font FACE="Courier" SIZE="2">t2</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">.</font><font FACE="Courier" SIZE="2" COLOR="#ff0000">rowID</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">)</font><font FACE="Courier" SIZE="2">
</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">from</font><font FACE="Courier" SIZE="2">
<font color="#808000">table1</font> t2</p>
<p style="margin-top: 0; margin-bottom: 0"></font>
<font FACE="Courier" SIZE="2" COLOR="#0000ff">where</font><font FACE="Courier" SIZE="2">
t1</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">.</font><font face="Courier" size="2">Datein
= t2.Datein</font></p>
<font FACE="Courier" SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"></font>
<font FACE="Courier" SIZE="2" COLOR="#0000ff">and</font><font FACE="Courier" SIZE="2">
t1</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">.</font><font FACE="Courier" SIZE="2">Status
</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">=</font><font FACE="Courier" SIZE="2">
t2</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">.</font><font FACE="Courier" SIZE="2">Status</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font FACE="Courier" SIZE="2" COLOR="#0000ff">and</font><font FACE="Courier" SIZE="2">
t1</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">.</font>UserIdin
<font FACE="Courier" SIZE="2" COLOR="#0000ff">=</font><font FACE="Courier" SIZE="2">
t2</font><font FACE="Courier" SIZE="2" COLOR="#0000ff">.</font>UserIdin
<font FACE="Courier" SIZE="2" COLOR="#0000ff">order by t2.timein);</font></p>
<p style="margin-top: 0; margin-bottom: 0"> </p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier" size="2">Thanks
in advancedHi Rob,
Just trying to chip in little bit!
Created Table As follows same as you, only two rows with duplicatem user, datein, and timein:
create table table1
as
select '08:20:00' timein, date '2007-09-01' datein, '0001' locationin, 'U01' useridin, 1 status from dual union all
select '08:10:30', date '2007-09-01', '0004', 'U01', 1 from dual union all
select '07:20:00', date '2007-09-01', '0006', 'U01', 1 from dual union all
select '08:14:00', date '2007-09-01', '0001', 'U02', 1 from dual union all
select '06:10:30', date '2007-09-01', '0004', 'U02', 1 from dual union all
select '06:10:30', date '2007-09-01', '0001', 'U02', 1 from dual
If I run your delete statement result row will be as follows:
SQL> select * from table1;
TIMEIN DATEIN LOCA USE STATUS
07:20:00 01-SEP-07 0006 U01 1
06:10:30 01-SEP-07 0004 U02 1
06:10:30 01-SEP-07 0001 U02 1
Here problem is that its not able to delete duplicate rows having same timein and timeout.
So I changed you query as follows:
DELETE FROM tab1
WHERE rowid NOT IN (
SELECT MIN(rowid)
FROM tab1
WHERE (UseridIn, TO_DATE(TO_CHAR(DateIn,'YYYYMMDD') || TimeIn,'YYYYMMDDHH24:MI:SS')) IN
( SELECT UseridIn, MIN(TO_DATE(TO_CHAR(DateIn,'YYYYMMDD') || timein,'YYYYMMDDHH24:MI:SS'))
FROM tab1
GROUP BY UseridIn)
GROUP BY UseridIn
If I run your delete statement with little bit of changes, the result row was as follows:
SQL> select * from table1;
TIMEIN DATEIN LOCA USE STATUS
07:20:00 01-SEP-07 0006 U01 1
06:10:30 01-SEP-07 0004 U02 1
Regards,
Raj -
How to get duplicate rows in a large table
I have a table which consists of 26 columns and 2 milion records..while doing validation i suspect there are duplicate records in that table...
Is there any way to check duplicate rows in a table?I went through link..in all the messages query is for 2 or 3 columns...but my scenario is i have 26 columns ...and i suspect there is duplicate row inserting .for which value is same for all 26 columns .how should i do .?
do i need to do group by all 26 columns and do having count(*) ...26 times? -
Selecting duplicate rows based on a combination of columns as key
Hi ,
I have a table with 5 columns.
Code ID S_DATE E_DATE Name
1 23 01012001 null ABC
1 09 01012001 null XYZ
2 81 04022007 null TVU
1 43 03092008 null XXX
Now, I need write a select query to fetch the duplicate rows from the above table having the combination of (Code, S_DATE,E_DATE) as the key.
So from the above example, I need to get Row1 and Row2 as output (but not Row3 as it has a different S_DATE)
Thanks in advance for your suggestions.
Thanks
Edited by: thotaramesh on Mar 9, 2009 4:54 PMOn XE;
WITH sample_data AS (
SELECT 1 code,23 ID, '01012001' s_date, null e_date, 'ABC' NAME FROM dual UNION ALL
SELECT 1, 09, '01012001', null, 'XYZ' FROM dual UNION ALL
SELECT 2, 81, '04022007', null, 'TVU' FROM dual UNION ALL
SELECT 1, 43, '03092008', null, 'XXX' FROM dual)
SELECT code, ID, s_date, e_date, NAME
FROM (
SELECT
sample_data.*,
COUNT(*) over (PARTITION BY code, s_date, e_date) dups
FROM sample_data)
WHERE dups > 1;
CODE ID S_DATE E_DATE NAME
1 23 01012001 ABC
1 9 01012001 XYZ
Maybe you are looking for
-
View updates on a machine w/out update policy
Is it possible to see if a machine has installed/hasn't installed updates even if it does not have an update policy enforced? The goal is to monitor machines without imposing an update policy while being able to see if they are regularly updating the
-
How to update my iPad?
-
Hi, I am trying to construct a PO report across all org id's and I cannot find all the info in the tables. When I run the query on the PO Views it is restricted to one Org ID Is there any way around this? Thanks Mick
-
Posting Level 01 documents allow cross company postings - unexpected
hi, Previously users could not enter a PL01 document that crossed companies. Now they can. I had previously thought that this was not possible for PL01 but what is happening is when they enter cross-company postings (2 lines, one each to a different
-
Price Difference in Passport (India)
Why is it that the Passport is available for $599 in the US and Rs46,000 ($760) in India???? Solved! Go to Solution.