SQL Server 2012 :: How To Delete Duplicate Rows Present In Parent Table

Oct 19, 2014

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.

-- ===============================================================================================
-- STORED PROCEDURE FOR FLATFILE_INVENTORY
-- ===============================================================================================
USE [IconicMarketing]
---=======================================SALES_CURSUR===========================================
--USE IconicMarketing
--GO
DECLARE
@FileType varchar(50) ,
@ACDealerID varchar(50) ,

[code].....

View 2 Replies


ADVERTISEMENT

SQL Server 2008 :: Delete Duplicate Rows From ANY Table

Jul 31, 2015

Is there is 'fairly' simple query to delete duplicate rows from ANY table ?

A script which removes duplicates from a table, when a table_name is supplied.

View 9 Replies View Related

Delete Child Table Rows Based On Predicates In A Parent Table

Jul 20, 2005

I have two tables that are related by keys. For instance,Table employee {last_name char(40) not null,first_name char(40) not null,department_name char(40) not null,age int not null,...}Employee table has a primary key (combination of last_name and first_name).Table address {last_name char(40) not null,first_name char(40) not null,street char(200) not null,city char(100) not null,...}Address table has a primary key (combination of last_name, first_name andstreet in which (last_name, first_name) reference (last_name, first_name) inemployee table.Now I want to delete some rows in Address table based on department_name inEmployee table. What is sql for this delete?I appreciate your help. Please ignore table design and I just use it for myproblem illustration.Jim

View 1 Replies View Related

Transact SQL :: Delete Duplicate Rows From Table?

Jul 21, 2015

I have a table with more than 1000 records. The columns look like this

Import id   |   Reference   |  Date  |  Username  | Filename

Some of the rows are duplicates except for the fact that they have different values for the first column alone (import id)

11111      test   21-07-2015   xxxxxx   yyyyyy
22222      test   21-07-2015   xxxxxx   yyyyyy

Is it possible to delete these kind of duplicate rows by ignoring the import id ?

View 9 Replies View Related

Delete Duplicate Rows From Two Tables With Same Structure In Sql Server 2000

Aug 20, 2007

Hi

I want to delete the duplicate rows from two tables and get the resultant non-duplicate rows from both the tables into another table

View 4 Replies View Related

SQL Server 2012 :: How To Find Particular Table Is Present In Which Database

Jan 19, 2014

I have created a table but i forget in which database. I know the table name but i dont know the database name..

I have to filter my table from all database ... how can i do and find....

View 5 Replies View Related

SQL Server 2012 :: Statement To Group Rows As Multiple Child Under Single Parent?

Sep 18, 2014

I've 2 tables QuestionAnswers and ConditionalQuestions and fetching data from them using CTE join and I'm seeing repetitive rows (not duplicate) like, If you have multiple answers for 1 question, the output is like

where london
where paris
where toronto

why us
why japan
why indonesia

I want to eliminate the repetitive question and group them as parent child items.

with cte as (
select cq.ConditionalQuestionID from ConditionalQuestions cq
inner join QuestionAnswers qa on cq.QuestionID=qa.QuestionID where cq.QuestionID=5 and qa.IsConditional='Y')
select distinct q.Question, a.Answer from QuestionAnswers qa
inner join Answers a on a.AnswerID = qa.AnswerID
inner join Questions q on q.QuestionID = qa.QuestionID
inner join cte c on c.ConditionalQuestionID = qa.QuestionID;

View 4 Replies View Related

Get All Children Of A Parent If Present Or Parent Itself?

Nov 21, 2012

I have the below query which in turn goes in the where clause

Code:

SELECT CASE WHEN EXISTS (SELECT child.id FROM InspectionType parent,
InspectionType child WHERE parent.id = child.parentId AND
parent.code = 'INSPECTION_TYPE_SAFETY_LIFE' AND parent.zoneId = 10129)
THEN (SELECT child.id FROM InspectionType parent, InspectionType child
WHERE parent.id = child.parentId AND parent.code ='INSPECTION_TYPE_SAFETY_LIFE' AND parent.zoneId = 10129)
ELSE (SELECT id FROM InspectionType WHERE code = 'INSPECTION_TYPE_SAFETY_LIFE' AND zoneId = 10129)
END

I am getting below error

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

I tried to solve this problem with If and else but it is not going well with in-clause

Code:
select * from InspectionType where id in (select IF EXISTS (SELECT child.id FROM InspectionType parent,
InspectionType child WHERE parent.id = child.parentId AND
parent.code = 'INSPECTION_TYPE_SAFETY_LIFE' AND parent.zoneId = 10129)
BEGIN (SELECT child.id FROM InspectionType parent, InspectionType child
WHERE parent.id = child.parentId AND parent.code ='INSPECTION_TYPE_SAFETY_LIFE' AND parent.zoneId = 10129)
END
ELSE (SELECT id FROM InspectionType WHERE code = 'INSPECTION_TYPE_SAFETY_LIFE' AND zoneId = 10129) )

I am using select * from InspectionType where id in() for illustation only. The sub-query results will go another query

Code:
SELECT child.id FROM InspectionType parent, InspectionType child
WHERE parent.id = child.parentId AND parent.code ='INSPECTION_TYPE_SAFETY_LIFE' AND parent.zoneId = 10129

This returns more than one row.I know why is the error message but need to achieve this functionality.

View 1 Replies View Related

Delete Records In SQL Table, Which Are Present In Excel

May 5, 2006

Hi everyone,

I have a task to create a dts package, which will delete records in a SQL table, which are present on a sheet tab in Excel. I know how to transfer records from Excel to SQL table and vice versa, but not sure how I can delete the records in SQL table, which are present in Excel. Note that there are just 2 columns - one is a key and the other name.

Thank you all in advance,
Saurav

View 1 Replies View Related

SQL Server 2012 :: Dropping Rows With Duplicate Column Name

Feb 13, 2014

I have a query that produces unique rows. However, some of the unique rows have the column called testname that has the same test listed more than once. All I want to do is drop the older testname and keep the testdate column.

Select
Distinct
TestID,
TestDate,
TestName

From third.test

I want to keep testdate in the query....guessing I need to put in to a temp table then drop the oldest one somehow by doing a subquery using Select Max....

View 1 Replies View Related

Delete Duplicate Rows

Jun 25, 2000

I have a table which looks as follow:

field1 field2 field3 field4 field5 ......
A B C A X ......
A B C B Y ......
A B C C Z ......
A B C A Y ......
. . . . . ......

I want to delete all the rows except one row. Anybody can help?

Thank you very much.

View 3 Replies View Related

Delete Duplicate Rows Using T-SQL

Jan 20, 2000

How do you delete duplicate rows in a table so only one row is left in the table, using T-SQL.

View 1 Replies View Related

DELETE DUPLICATE ROWS

Mar 30, 1999

CAN ANYBODY REPLY FOLLOWING QUESTIONS. I WANT TO DELETE DUPLICATE ROWS
IN MY TABLE WITHOUT USING TRANSACTION TABLE. AND ONE MORE QUESTION HOW
TO GET YESTERDAY DATE BY USING ISQL WINDOW.



THANKS
JK

View 2 Replies View Related

Delete Duplicate Rows

Jan 13, 2005

Suppose that we have the following rows in a MSSQL table :


1administrateur1NULLNULL
2administrateur2NULLNULL
1administrateur1NULLNULL
2administrateur2NULLNULL



How to remove duplicates (leave only the 2 first rows) ?

View 1 Replies View Related

Delete Duplicate Rows

Oct 17, 2005

Hi,
I have the following query to select duplicate rows from the table. How can i delete them with out using temp table.

select UserName, Title, Name, ColWidth, Sequence
from table1 (nolock))
Group by UserName, Title, Name, ColWidth, Sequence
Having count(*) >1


Any help would be greately appreciated.
Thanks

View 2 Replies View Related

Delete Duplicate ROWS

Jun 18, 2008

How to delete duplicate records from table ? Is there any query for that ?
I am using SQL 2005.

View 3 Replies View Related

Delete Duplicate Rows

Jan 27, 2014

declare @a1 table
(id int not null identity(1,1),
phone decimal(18,0),
adress nvarchar(100))
insert @a1
(phone,adress)

[Code] ....

id phone address
----------- --------------------------------------- ----------------------------------------------------------------------------------------------------
1 111 new york
2 111 new york
3 111 new york
4 222 maxico
5 222 mexico

select phone,count(phone) as say from @a1 group by phone having count(phone)>1

phone say
--------------------------------------- -----------
111 3
222 2

How can I remove duplicate phone. For example

after delete
select*from @a1
select*from @a1

id phone address
----------- --------------------------------------- ----------------------------------------------------------------------------------------------------
1 111 new york
4 222 maxico

I wrote this to show for example in my real table have 50000 rows and 1751 duplicate rows.

[URL] .....

View 2 Replies View Related

How Do You Delete Duplicate Rows......

Jan 18, 2006

How do you delete duplicate rows when there are constraints or like in professional terms as we say "Referential Integrity".

Mr.Madhivanan i hope you remember me. Because it is after all purpose that binds us all together...purpose...it is inevitable Mr.Madhivanan.

View 8 Replies View Related

How To Delete Duplicate Rows Retaining Only One Of Them From Every Set Of Duplicates.

Apr 10, 2008

 
I have a table employee_test having the sample data. The rows with EmployeeID=6 are duplicate rows. I want to delete the duplicates retaining one row for the employeeid=6.
Note :- I don't want to use a temporary table. I want to do this using a single query or at the most in a SP query batch. Please advise. 




EMPLOYEEID

ENAME

SALARY

MANAGERID


1

Anee

1000

11


2

Rick

1200

12


3

JOHN

1100

13


4

ABC

1300

14


5

DEF

1400

15


6

DEF

1400

15


6

DEF

1400

15

View 22 Replies View Related

Delete Duplicate Rows With No Unique Columns

Apr 3, 2000

I have 4 rows which are exactly the same. I want to delete one row but i do not have any unique identifing columns. How should i delete that row ?

View 1 Replies View Related

Need A Stored Procedure To Delete Duplicate Rows

Oct 22, 2007

hi every body

can any onehelp me in making a stored procedure to delete a duplicate rows in tables

thanks in advance

View 9 Replies View Related

SQL Server 2012 :: Query To Select Parent Details From Child Table

Mar 3, 2015

I have a scenario,

We have equipment table which stores Equipment_ID,Code,Parent_Id etc..for each Equipment_ID there is a Parent_Id. The PK is Equipment_ID Now i want to select the Code for the Parent_Id which also sits in the same table. All the Parent_Id's also are Equipment_ID's.

Equipment table looks like :

Equipment_ID Code DescriptionTreeLevelParent_Id
6132 S2611aaa 4 6130
11165 V2546bbb 3 1022
15211 PF_EUccc 5 15192
39539 VP266ddd 4 35200
5696 KA273eee 3 3215
39307 VM2611fff 4 35163
39398 IK264ggg 4 35177

There is another table for Equipment_Tree which has got Equipment_Tree_ID,Parent_Id and Equipment_ID does not has the Code here.

Select query where i need to select the Code for all Parent_Id's.

View 8 Replies View Related

SQL Server 2012 :: Strategy To Delete / Move Millions Of Rows In A Database?

Apr 16, 2015

I am using SQL Server 2012 SE.I am trying to delete rows from a couple of tables (GetPersonValue has 250 million rows and I am trying to delete 50Million rows and GetPerson has 35 Million rows and I am trying to delete 20 million rows). These tables are in TX replication.The plan is to delete data older than 400 days old.

I tried to move data to new tables from the last 400 days and it took me like 11 hours. If I delete data in chunks of 500000 then its taking a long time to rebuild indexes(delete plus rebuild indexes 13 hours). Since I am using standard edition partition wont work.

find ddl below:

GO
CREATE TABLE [dbo].[GetPerson](
[GetPersonId] [uniqueidentifier] NOT NULL,
[LinedActivityPersonId] [uniqueidentifier] NOT NULL,
[CTName] [nvarchar](100) NULL,
[SNum] [nvarchar](50) NULL,
[PHPrimary] [nvarchar](50) NULL,

[code]....

View 1 Replies View Related

SQL Server 2012 :: Query To Generate Relationship (Parent Child Hierarchy From A Table)

Jul 18, 2015

I am working on a query to generate parent child hierarchy from a table.

Table has below records.

--===== If the test table already exists, drop it
IF OBJECT_ID('TempDB..#mytable','U') IS NOT NULL
DROP TABLE #mytable

--===== Create the test table with
CREATE TABLE #mytable

[Code] ...

how to achieve this.l tried with temp tables it doesn't work.

View 5 Replies View Related

SQL 2012 :: Delete Rows If Member Does Not Exists In The Member Table

Sep 24, 2015

I have a table where I need to delete rows if the member does not exists in the member table. Will the following syntax work ?

Delete T
FROM Event_Temp_Lead_Screen T
left join member M on ( M.MemberID = T.MemberID )
where
T.Gender is NULL

View 9 Replies View Related

SQL 2012 :: Get Maximum Row Number For Duplicate Valued Rows

May 20, 2015

I have a table which dont any Identity column. The data in the table has duplicate values, some rows are totally identical. I just want to select the row which has maximum Row Id/Row number if I am getting multiple rows in my select statement.

View 2 Replies View Related

How To Delete Duplicate Records From A Table

Nov 29, 2004

Hello All,

Please show me how to delete duplicate records from a table.


Thanks in Advance

View 1 Replies View Related

Auto Delete Duplicate Value From Table

Nov 6, 2014

I have one table with 5 field, one of the field having unique values, and every month i append this table by using import/export wizard from excel, and that excel having some new value and some old value which is already in sql table, now i want such duplicate value delete automatic at the time of append the table or after that,

Currently i am doing this in excel, i delete duplicate data in excel and upload again whole data in sql.

View 1 Replies View Related

How To Delete Duplicate Records From A Table ?

Jul 20, 2005

I uploaded some data about 2 or 3 times and it keep appending it to thetable.Now I want to keep only first duplicate and delete rest of.Suppose part number 123 has been added 3 times so I want to keep only 1record.Thanks

View 1 Replies View Related

How To Delete Duplicate Records From Table ?

Mar 4, 2008

Hello Frnds....Can anybody give the answer of this question as How to Delete duplicate records from Table ?
I Know that with check option and also with Unique Constraint we can avoid to enter duplicate records in table but How to delete from table which does not have any constraints ?

View 8 Replies View Related

SQL Server 2012 :: How To Get Primary Key Value If Not Present In Foreign Key Via Join

May 4, 2014

I've following query which display the result as required, but I need to get the missing Primary Key Values which are not available in the result:

SELECTA.SignedByUserID, B.FullName, COUNT(A.OutletID) AS TotalSignups, DATENAME(Month, A.SignupDate) AS Month
FROMdbo.tblMer_Outlet AS A LEFT OUTER JOIN dbo.tblGen_Users AS B ON A.SignedByUserID = B.UserID
WHERE(A.SignupDate >= '2014-04-01 00:00:00' AND A.SignupDate <= '2014-04-30 23:59:59')
GROUP BY A.SignedByUserID, B.FullName, DATENAME(Month, A.SignupDate)

This Query returns the following result:

SignedByUserID FullName TotalSignups Month
--------------------------------------------------------
9 Babu Raj 16 April
11 Faheem 19 April
39 Fasil Abbas 16 April
29 Hafiz Suleman 10 April

[code]....

which does not have a signup for the month of April, but I need it to be available for this or any upcoming month. I need this orr all users, which does not exists in the context needs to be displayed in the result.

View 9 Replies View Related

SQL Server 2012 :: How To Batch Delete Large Table

Jun 16, 2015

I have a table with about 466 Million rows. In this table there is a int column called WeeksToRetain as well as a EventDate column containing the date the row was inserted. I am trying to delete all the rows that that should be deleted according to the WeeksToRetain. For example, if the EventDate is 5/07/15 with a 1 in the WeeksToRetain column the row should be removed by 5/14/15. I am not sure what days SQL considers the beginning and end of the week. However the core issue I am having is the sheer mass of deletions I must do and log growth.

So I am trying to do the delete in batches. More specifically I want to load a temporary table with a million rows, then use the temporary table to load a sub temporary table with 100,000 rows and join this temporary table to the table I want to delete from looping through 10 times to get 1 million. The Logging.EvenLog table which is the table I'm trying to purge has a clustered index on EventDate (ASC). I would like to run this in a schedule job with enough time between executions for log backups to run.

DECLARE @i int
DECLARE @RowCount int
DECLARE @NextBatchDate datetime
CREATE TABLE #BatchProcess
(
EventDate datetime,
ApplicationID int,

[Code] .....

View 9 Replies View Related

Transact SQL :: Table Trigger To Delete All Rows Before Inserting Rows

Jul 24, 2015

I have a SQL script to insert data into a table as below:

INSERT into [SRV1INS2].BB.dbo.Agents2
select * from [SRV2INS14].DD.dbo.Agents

I just want to set a Trigger on Agents2 Table, which could delete all rows in the table , before carry out any Insert operation using above statement.I had below Table Trigger on [SRV1INS2].BB.dbo.Agents2 Table as below: But it did not perform what I intend to do.

USE [BB]
GO
/****** Object:  Trigger    Script Date: 24/07/2015 3:41:38 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON

[code]....

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved