Avatar of isames
isames
 asked on

SQL Query Delete

I have a SQL job that runs every night at 10PM. It has three tasks. The first task runs a query against my Canada db populating a table called ToolsOnRent with Canada tools with a status of R.

The second task does the same thing for US.

The third task validates.

When the job ran on 8-11-15, it failed after the 1st task. So i re-ran the job after receiving the failure email. The job ran successfully.

However, when I got into the office this morning, i noticed that Canada rows were duplicated for any tools that has a Rent status on 8-11-15.

Below is a screenshot. I just chose a couple of the serial numbers i knew belong to tools that were rented by a Canadian store. The Canadian store numbers all begin with 07. The embedded screenshot also shows how the table is structured.

SQL Table that shows example of duplicated rows
How do I delete all of the duplicated rows for just the Canadian stores that begin with 07 for 8-11-15?
Microsoft SQL ServerMicrosoft SQL Server 2008

Avatar of undefined
Last Comment
ste5an

8/22/2022 - Mon
Vitor Montalvão

They aren't duplicate rows. They have different values for some columns.
Anyway, if you want to delete the duplicate rows, which one should be kept and which one should be deleted?
ASKER CERTIFIED SOLUTION
Guy Hengel [angelIII / a3]

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ste5an

And use an appropriate primary key and additional unique constraints..
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23