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 |
|
voyager838
Yak Posting Veteran
90 Posts |
Posted - 2010-06-21 : 07:13:12
|
| HiI need to create an query where i compare two tablesand update change in records and also insert new records if it isn't exists yet.An combination with UPDATE and INSERT, or is the best way to split it up in two separated querys? |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-06-21 : 08:09:58
|
In 2005 it is not possible but in 2008.In 2005 do an update first and after that an insert with where not exists() No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-06-21 : 09:39:27
|
| In 2008 you can do it using Merge statement.http://technet.microsoft.com/en-us/library/bb510625.aspxIf I am not mistaken Oracle supported it from 9i .Dont know why Microsoft waited till 2008 release to implement it.Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH |
 |
|
|
voyager838
Yak Posting Veteran
90 Posts |
Posted - 2010-06-21 : 13:58:26
|
| Thanks WebFred and Idera. You are right bothMerge is one way, unfortunate i dont have 2008, and it came to my conclusion also thatit was best to do an update-query first and second make an insert-query.Thanks |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-06-21 : 14:04:58
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|