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 |
sathiesh2005
Yak Posting Veteran
85 Posts |
Posted - 2010-06-09 : 00:26:16
|
Hi,I am using cursors in my SP to get last n days records and transfer them to another sql server database through linked server.My need is to get the last n days records and update them if it already exist otherwise i am inserting the new record. Its running successful for the last 2 years but day by day its taking more time to complete the task.I think using cursors is not a best way. so i need a better alternate for this.Please suggest me how to do this.Thanks in advance.Regards,Sathieshkumar. R |
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-06-09 : 01:06:55
|
This may help you.1.Insert the record not from source to destination table - USE "Not exists"2.Put a inner join and update the older record in the destination table.Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
|
|
sathiesh2005
Yak Posting Veteran
85 Posts |
Posted - 2010-06-09 : 05:45:16
|
Hi Senthil,Thank you. It works for me in single database.I am now trying this for my actual purpose using the linked server from different servers.thanks for your reply.Regards,Sathieshkumar. R |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-06-09 : 06:17:04
|
Make update first and after that comes the insert.Because then the update has less to do. No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
sathiesh2005
Yak Posting Veteran
85 Posts |
Posted - 2010-06-10 : 00:58:11
|
hi,I have completed the task using exist clause.Thank you senthil & webfred for your kind reply.Regards,Sathieshkumar. R |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2010-06-10 : 01:07:50
|
Welcome! :)Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
|
|
|
|
|