Skip to content

Instantly share code, notes, and snippets.

@Dillie-O
Created June 3, 2013 19:45
Show Gist options
  • Save Dillie-O/5700786 to your computer and use it in GitHub Desktop.
Save Dillie-O/5700786 to your computer and use it in GitHub Desktop.
Advanced Remove Duplicate Row Delete Snippet
DELETE application_versions FROM
(
SELECT TOP (@duplicate_count - 1) id
FROM application_versions
WHERE (@application_id IS NULL OR application_id = @application_id)
AND (@lock_version IS NULL OR lock_version = @lock_version)
AND (@asset_id IS NULL OR asset_id = @asset_id)
AND (@customer_id IS NULL OR customer_id = @customer_id)
AND (@received_date IS NULL OR received_date = @received_date)
AND (@fee_amount IS NULL OR fee_amount = @fee_amount)
AND (@created_at IS NULL OR created_at = @created_at)
AND (@updated_at IS NULL OR updated_at = @updated_at)
) AS t1
WHERE application_versions.id = t1.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment