Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ragh
Starting Member
34 Posts |
Posted - 2003-01-18 : 00:41:25
|
| I have two servers 1. Infoprod12. Infoprod2I have two databases Db1 sits in infoprod1Db2 sits in infoprod2My table structure of db1 is like this--------------------------------------Field Name Table Name Tb_M_IssuesIssue_ID Primary Key Auto Gen keyIss_VolumeIss_NumberIss_PartIss_SupplimentryJournal_IDIss_DateIss_MonthIss_YearSort_OrderLast_ModifiedActive_flag ======================================================================My table structure of db2 is like this--------------------------------------Field Name Table Name Tb_M_IssuesIssue_ID Primary Key Auto Gen keyIss_VolumeIss_NumberIss_PartIss_SupplimentryJournal_IDIss_DateIss_MonthIss_YearSort_OrderLast_ModifiedActive_flagIss_Source Source name for eg: db1Source_ID Issue id of db1----------------------------------------------------------------------Now I have to write one dts script the data from infoprod1 should be transferred to infoprod2 daily.There is a chance of modifying of existing record in db1 so this record should b updated instead of inserting it. Please let me know how to do it. Hope u r clear abt this. If u hv any doubt pl. ask me.regardsRagh |
|
|
ValterBorges
Master Smack Fu Yak Hacker
1429 Posts |
Posted - 2003-01-18 : 14:04:49
|
| Well you can either use dts or linked the servers.If you dts create a temp table in the db2 which contains the table in db1.What I would suggest is that you do three queries.First delete where it doesn't exist any longer or mark inactiveex:/* Transact-SQL extension */USE pubsDELETE titleauthorFROM titleauthor LEFT JOIN titles ON titleauthor.title_id = titles.title_idWHERE titles.title IS NULLyour where clause should specify where pk's of right table is nullNext Insert where it doesn't exist db1.table left join db2.tablewhere db2.table.pkid is Null--INSERT...SELECT exampleUSE pubsINSERT author_sales SELECT authors.au_id FROM authors LEFT JOIN titleauthor ON authors.au_id = titleauthor.au_id WHERE titleauthor.au_id IS NULLyour where clause should specify where pk's of right table is nullThen update (last for referential integrity issues when updating multiple tables)ex:UPDATE titles SET ytd_sales = titles.ytd_sales + sales.qty FROM titles, sales WHERE titles.title_id = sales.title_id AND sales.ord_date = (SELECT MAX(sales.ord_date) FROM sales)make sure you're where clause specifies how to determine when two records are equalEdited by - ValterBorges on 01/18/2003 14:06:49 |
 |
|
|
|
|
|