Home > Archive > Microsoft SQL Server forum > January 2006 > How can I update several (not all) fields in table A from table B for replication?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How can I update several (not all) fields in table A from table B for replication?
M Bourgon

2006-01-19, 8:24 pm

I am trying to update the contents of table A (I'll use
Northwind..Products as an example) with the data from any changed
fields in Table B (which is a copy of Northwind..Products, but with
some updated values). Table_A is replicated, so I would rather not
update every field, but just the fields where the values are different.


I could probably due it using dynamic SQL, but for many obvious reasons
I'd prefer not to. And the reason for Table_B is replication - when we
get a "comprehensive" file we delete and start anew (and yes, there's a
reason for this as well), rather than just update the original.

The only way I've thought of is to do one for each field, something
like:

update products
set productname = products2.productname
from products, products
where products.id = products2.id and products.productname <>
products2.productname

update products
set supplierid = products2.supplerid
[...]

Any help greatly appreciated. I considered trying some kind of CASE
clause that would set it to its own value (set productname =
products.productname), but that would (?) be considered a change and
would be replicated.

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com