Link to home
Start Free TrialLog in
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.

User generated image
How do I delete all of the duplicated rows for just the Canadian stores that begin with 07 for 8-11-15?
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

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
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And use an appropriate primary key and additional unique constraints..