January 29, 2013 at 10:41 am
Hi all,
[SQL Server 2008R2]
I have 2 tables on different servers that I need to keep in-sync.
I have access to tableB on serverB from serverA via linked_server (one way only).
This is how I find rows that are different:
select * from tableA a
where not exists (select 1 from linked_server.db.shema.tableB b
where a.col1 = b.col1
and a.col2 = b.col2
and a.col3 = b.col3
)
How do I turn this into an update?
In short I need to update remote table (linked_server.db.shema.tableB) from a result of a query.
Forgot to mention that I found this way, but couldn't make it work:
execute ('your sql command here') at my_linked_server
I was also told that I can use "openquery" and trying to find examples of that.
Thanks,
January 29, 2013 at 10:50 am
Incredibly sparse on details. You just need to create your update statement.
Something like this.
update alias
set Col = slt.val
from linkserver.database.schema.table alias
join SomeLocalTable slt on slt.ID = alias.ID
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
January 29, 2013 at 11:57 am
Will this update all rows in the tableB?
I need to update rows that are different.
January 29, 2013 at 12:17 pm
I gave you a basic syntax. Given the lack of details that is the best I can do. All you need to do is figure out what the query is to get the rows you want to update and the columns you need updated. If you need more specific help you need to provide us with ddl, sample data and desired results based on your sample data. Please see the first link in my signature for best practices when posting questions.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply