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 |
|
azaza
Starting Member
4 Posts |
Posted - 2011-09-08 : 12:12:25
|
| I am trying to merge some tables here, but continue to get error. Can anybody give me a quick accessment on what I am doing wrong?See a partial view of the script below:MERGE into Recipient AS D USING (SELECT * FROM temp_Recipient WHERE recordID in (select recordId from temp_recipient)AND recordID not in (select recordId from recipient)) S ON (D.recordID = S.recordID)WHEN MATCHED THEN UPDATE SETD.RecordID = s.RecordID , D.apps_type = s.apps_type , D.DateSubmitted = s.DateSubmitted , );Here is the error:Msg 156, Level 15, State 1, Line 1Incorrect syntax near the keyword 'into'.Msg 102, Level 15, State 1, Line 3Incorrect syntax near 'S'.Resolution:I removed the into and tried MERGE <table_name> aliasusing (select......)But still get error. |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-09-08 : 12:17:59
|
| you have a stray comma and parenteses at the end.this parses:MERGE into Recipient AS D USING (SELECT * FROM temp_Recipient WHERE recordID in (select recordId from temp_recipient)AND recordID not in (select recordId from recipient)) S ON D.recordID = S.recordIDWHEN MATCHED THEN UPDATE SETD.RecordID = s.RecordID , D.apps_type = s.apps_type , D.DateSubmitted = s.DateSubmitted; |
 |
|
|
azaza
Starting Member
4 Posts |
Posted - 2011-09-08 : 12:38:33
|
| I am sorry it didn't work as you can see from the below error:Msg 156, Level 15, State 1, Line 1Incorrect syntax near the keyword 'INTO'. |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-09-08 : 12:44:16
|
| Are you using SQL Server 2008? |
 |
|
|
azaza
Starting Member
4 Posts |
Posted - 2011-09-08 : 14:24:39
|
| Yes I am using 2008 as client, but on 2005 server |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-09-08 : 14:25:33
|
| Merge won't work against 2005.MERGE is new with SQL 2008. |
 |
|
|
azaza
Starting Member
4 Posts |
Posted - 2011-09-08 : 14:32:02
|
| That might be the problem then - thanks a million |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-09-08 : 14:42:45
|
| Welcome. |
 |
|
|
|
|
|
|
|