SQL Query Delete

isames
isames used Ask the Experts™
on
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?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
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?
Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
Commented:
please see this article on how to decide on what Vitor indicates and to accordingly write the delete:
http://www.experts-exchange.com/articles/15139/SQL-Server-Delete-Duplicate-Rows-Solutions.html
ste5anSenior Developer

Commented:
And use an appropriate primary key and additional unique constraints..

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial