| Author |
Topic |
|
Bex
Aged Yak Warrior
580 Posts |
Posted - 2006-06-06 : 08:15:33
|
Does this new functionality exist in SQL Server 2005? The reason I ask, is because I cannot locate the merge function in BOL for T-SQL 2005. And when I type in the syntax it throws an error:IF OBJECT_ID('merge') IS NOT NULLDROP table mergecreate table merge( col1 int, col2 varchar(20))insert into mergeselect 1, 'hello'insert into mergeselect 2, 'goodbye'select into #tempcol1, col2 from mergeupdate #tempset col2 = 'Boo'select * from mergemerge into mergeusing #temp on #temp.col1 = merge.col1when matched then update col2 = #temp.col2when not matched theninsert values(#temp.col1,#temp.col2)The error I get is:Msg 156, Level 15, State 1, Line 15Incorrect syntax near the keyword 'into'.Msg 156, Level 15, State 1, Line 23Incorrect syntax near the keyword 'into'.Hearty head pats |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2006-06-06 : 08:33:58
|
| It doesn't exist.MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-06-06 : 08:49:50
|
| You can apply this logicUpdate Tset col2 = M.col2 from #temp T inner join Merge Mon T.col1=M.col1Insert into #temp(columns)Select Columns from Merger M where no exists(select * from #temp where col1=M.col1)MadhivananFailing to plan is Planning to fail |
 |
|
|
Bex
Aged Yak Warrior
580 Posts |
Posted - 2006-06-06 : 09:07:00
|
| Thankyou for the replies, and the solution of course! Darn shame about the upsert! I think thats just a big tease, exciting us with the prospect and then snatching it away! Bad microsoft!!!Hearty head pats |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-06-06 : 09:19:38
|
quote: Originally posted by Bex Thankyou for the replies, and the solution of course! Darn shame about the upsert! I think thats just a big tease, exciting us with the prospect and then snatching it away! Bad microsoft!!!Hearty head pats
Do you think Other RDBMSs support Upsert?MadhivananFailing to plan is Planning to fail |
 |
|
|
Bex
Aged Yak Warrior
580 Posts |
Posted - 2006-06-06 : 11:50:59
|
| I think Oracle does........Hearty head pats |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-06-07 : 02:50:58
|
quote: Originally posted by Bex I think Oracle does........Hearty head pats
Can you give us example query or the Link that explains Upsert?MadhivananFailing to plan is Planning to fail |
 |
|
|
Kristen
Test
22859 Posts |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-06-07 : 04:15:32
|
| Well. I remember I suggested this one sometimes agoUpdate.....If @@RowCount=0Insert.....MadhivananFailing to plan is Planning to fail |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-06-07 : 04:18:32
|
| If you look at the MERGE syntax for Oracle's implementation of UPSERT its loads more tortuous than that ...MERGE - specify all PK stuffthen specify separate INSERT and UPDATE statements for whether it exists, or not.The If @@RowCount=0 look tidier to me ... but I expect that Oracle's MERGE syntax optimises better than actually attempting an UPDATE and having it failover to an INSERT.Anyway, that's enough talk of Oracle before we both get thrown out of here!Kristen |
 |
|
|
|