Author |
Topic  |
|
JacobPressures
Posting Yak Master
112 Posts |
Posted - 03/28/2013 : 16:39:24
|
MERGE Batches b USING (SELECT ID, FileName, CdbConnection, RdbConnection, CustomerID FROM Batches WHERE FileName = 'ex_20121009_unity-ny-a' AND CdbConnection = '\\mwfs1avm\MWPRIVATE\macdog\ex_20121009_unity-ny-a') o ON o.ID = b.ID WHEN MATCHED THEN SELECT 'Match Found' WHEN NOT MATCHED THEN SELECT 'NO Match'; |
|
Lamprey
Flowing Fount of Yak Knowledge
4614 Posts |
Posted - 03/28/2013 : 16:54:40
|
Run it? |
 |
|
JacobPressures
Posting Yak Master
112 Posts |
Posted - 03/28/2013 : 16:59:35
|
I get this error: Msg 156, Level 15, State 1, Line 6 Incorrect syntax near the keyword 'SELECT'. |
 |
|
Lamprey
Flowing Fount of Yak Knowledge
4614 Posts |
|
JacobPressures
Posting Yak Master
112 Posts |
Posted - 03/28/2013 : 17:23:37
|
Actually the problem seems to be that you can't put a SELECT statement there thanks!
I'm trying to figure out how to TEST whether this is working or not. |
 |
|
James K
Flowing Fount of Yak Knowledge
3873 Posts |
Posted - 03/28/2013 : 17:47:10
|
As you found out, MERGE is a DML statement - you can think of it as a combination of update, insert and delete. So the "WHEN" sections have to have one of those.
One way you can test is to write your actual query that has the insert/update/delete's in the WHEN sections, begin a transaction, run the merge statement, examine the results and then rollback.
If it is a hot database/table that you don't want to leave locked (when the transaction is left open), you can use output clause along with your insert/update/deletes to output the results and rollback immediately. |
 |
|
|
Topic  |
|