Skip to content

[Comments] Only update rows that changed? Try using EXISTS and EXCEPT #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
chadbaldwin opened this issue Jan 17, 2021 · 2 comments
Labels

Comments

@chadbaldwin
Copy link
Owner

https://chadbaldwin.net/2020/12/30/only-update-rows-that-changed.html

@EitanBlumin
Copy link

Super-cool method! This is my new favorite thing now 😁

Copy link

Brilliant! I only had to change one thing. My table is being updated from a datadump table. It can have one or more records for a given Report, and the only difference in each **otherwise-identical Report is the included Person data (Type of Person, FirstName, LastName, Address, etc...) So the original USING statement in your code returns multiple records in my datadump table, which throws an error when doing the UPDATE statement.

I changed it to this:

USING (select top 1 with ties * from #Updates u order by row_number() over (PARTITION BY ReportNumber ORDER BY ID DESC)) d on d.ReportNumber = u.ReportNumber

...which only returns one record per unique ReportNumber

**Seriously, the group of folks who designed the datadump I receive every day needs to be forced to listen to an out-of-tune piano playing a duet with an out-of-tune bagpipes while a tone-deaf singer sings "Ave Maria" for the rest of their lives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants